PERF: finalize porting to new incoming links structure

This commit is contained in:
Sam
2014-08-04 16:43:57 +10:00
parent 22768a4b68
commit 03c8f09be8
14 changed files with 145 additions and 23 deletions

View File

@@ -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