Upgrade to support threads.
This commit is contained in:
parent
ff6423f2b7
commit
66137dcf7b
1 changed files with 9 additions and 11 deletions
|
@ -7,19 +7,17 @@ class Setting < ActiveRecord::Base
|
||||||
after_update :delete_cache
|
after_update :delete_cache
|
||||||
after_destroy :delete_cache
|
after_destroy :delete_cache
|
||||||
|
|
||||||
@@config = nil
|
|
||||||
|
|
||||||
def self.load
|
def self.load
|
||||||
|
|
||||||
# check if config is already generated
|
# check if config is already generated
|
||||||
return @@config if @@config
|
return Thread.current[:settings_config] if Thread.current[:settings_config]
|
||||||
|
|
||||||
# read all config settings
|
# read all config settings
|
||||||
config = {}
|
config = {}
|
||||||
Setting.select('name, state').order(:id).each { |setting|
|
Setting.select('name, state').order(:id).each { |setting|
|
||||||
config[setting.name] = setting.state[:value]
|
config[setting.name] = setting.state[:value]
|
||||||
}
|
}
|
||||||
|
|
||||||
# config lookups
|
# config lookups
|
||||||
config.each { |key, value|
|
config.each { |key, value|
|
||||||
next if value.class.to_s != 'String'
|
next if value.class.to_s != 'String'
|
||||||
|
@ -27,20 +25,20 @@ class Setting < ActiveRecord::Base
|
||||||
s = config[$1].to_s
|
s = config[$1].to_s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# store for class requests
|
# store for class requests
|
||||||
@@config = config
|
Thread.current[:settings_config] = config
|
||||||
return config
|
return config
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get(name)
|
def self.get(name)
|
||||||
self.load
|
self.load
|
||||||
return @@config[name]
|
return Thread.current[:settings_config][name]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def delete_cache
|
def delete_cache
|
||||||
@@config = nil
|
Thread.current[:settings_config] = nil
|
||||||
end
|
end
|
||||||
def set_initial
|
def set_initial
|
||||||
self.state_initial = self.state
|
self.state_initial = self.state
|
||||||
|
|
Loading…
Reference in a new issue