Optimize URL.database_available? (#16968)
This method was making a DB query every time. Chances are that if the table is there the first time, it'll continue to exist. This is an assumption generally baked into ActiveRecord - it caches the schema for every table when its corresponding model is used and never checks it again for the life of the process.
This commit is contained in:
parent
73ff4169e8
commit
2058c57274
1 changed files with 7 additions and 1 deletions
|
|
@ -5,11 +5,17 @@ module URL
|
|||
end
|
||||
|
||||
def self.database_available?
|
||||
ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?("site_configs")
|
||||
ActiveRecord::Base.connected? && has_site_configs?
|
||||
end
|
||||
|
||||
private_class_method :database_available?
|
||||
|
||||
def self.has_site_configs?
|
||||
@has_site_configs ||= ActiveRecord::Base.connection.table_exists?("site_configs")
|
||||
end
|
||||
|
||||
private_class_method :has_site_configs?
|
||||
|
||||
def self.domain
|
||||
if database_available?
|
||||
Settings::General.app_domain
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue