mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: finalize porting to new incoming links structure
This commit is contained in:
@@ -1,4 +1,32 @@
|
||||
class IncomingDomain < ActiveRecord::Base
|
||||
def self.add!(uri)
|
||||
name = uri.host
|
||||
https = uri.scheme == "https"
|
||||
port = uri.port
|
||||
|
||||
current = find_by(name: name, https: https, port: port)
|
||||
return current if current
|
||||
|
||||
# concurrency ...
|
||||
|
||||
begin
|
||||
current = create!(name: name, https: https, port: port)
|
||||
rescue
|
||||
# duplicate key is just ignored
|
||||
end
|
||||
|
||||
current || find_by(name: name, https: https, port: port)
|
||||
end
|
||||
|
||||
def to_url
|
||||
url = "http#{https ? "s" : ""}://#{name}"
|
||||
|
||||
if https && port != 443 || !https && port != 80
|
||||
url << ":#{port}"
|
||||
end
|
||||
|
||||
url
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
||||
Reference in New Issue
Block a user