From 66137dcf7bbfa0a3606556d58a8839dd30a686c4 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 28 Jul 2012 18:37:18 +0200 Subject: [PATCH] Upgrade to support threads. --- app/models/setting.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/models/setting.rb b/app/models/setting.rb index ea5db40d6..e2617a411 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -7,19 +7,17 @@ class Setting < ActiveRecord::Base after_update :delete_cache after_destroy :delete_cache - @@config = nil - def self.load - + # check if config is already generated - return @@config if @@config - + return Thread.current[:settings_config] if Thread.current[:settings_config] + # read all config settings config = {} Setting.select('name, state').order(:id).each { |setting| config[setting.name] = setting.state[:value] } - + # config lookups config.each { |key, value| next if value.class.to_s != 'String' @@ -27,20 +25,20 @@ class Setting < ActiveRecord::Base s = config[$1].to_s } } - + # store for class requests - @@config = config + Thread.current[:settings_config] = config return config end def self.get(name) self.load - return @@config[name] + return Thread.current[:settings_config][name] end - + private def delete_cache - @@config = nil + Thread.current[:settings_config] = nil end def set_initial self.state_initial = self.state