Project

General

Profile

Patch #1321 » 0001-precache-all-settings.patch

preload settings - Philip Hofstetter, 2008-05-28 22:56

View differences:

app/models/setting.rb
41 41
    @@available_settings["plugin_#{id}"] = {'default' => plugin.settings[:default], 'serialized' => true}    
42 42
  end
43 43
  
44
  @@settings = {}
45
  find(:all).each do |setting|
46
    @@settings[setting.name] = setting
47
  end
48
  
44 49
  validates_uniqueness_of :name
45 50
  validates_inclusion_of :name, :in => @@available_settings.keys
46 51
  validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' }  
......
119 124
  def self.find_or_default(name)
120 125
    name = name.to_s
121 126
    raise "There's no setting named #{name}" unless @@available_settings.has_key?(name)    
122
    setting = find_by_name(name)
127
    setting = @@settings[name] if @@settings.has_key? name
123 128
    setting ||= new(:name => name, :value => @@available_settings[name]['default']) if @@available_settings.has_key? name
124 129
  end
125 130
end
(1-1/2)