PERF: avoid looking globals from providers after first call

This commit is contained in:
Sam 2017-03-09 18:00:55 -05:00
parent b68d08404d
commit 3032aa7db9
1 changed files with 14 additions and 1 deletions

View File

@ -39,8 +39,21 @@ class GlobalSetting
default_provider = FileProvider.from(File.expand_path('../../../config/discourse_defaults.conf', __FILE__))
default_provider.keys.concat(@provider.keys).uniq.each do |key|
default = default_provider.lookup(key, nil)
instance_variable_set("@#{key}_cache", nil)
define_singleton_method(key) do
provider.lookup(key, default)
val = instance_variable_get("@#{key}_cache")
unless val.nil?
val == :missing ? nil : val
else
val = provider.lookup(key, default)
if val.nil?
val = :missing
end
instance_variable_set("@#{key}_cache", val)
val == :missing ? nil : val
end
end
end
end