Merge pull request #626 from opf/fix/settings_performance

Settings: Cache whether settings table exists
pull/624/head
Philipp Tessenow 11 years ago
commit 9f68eec04d
  1. 15
      app/models/setting.rb
  2. 1
      doc/CHANGELOG.md

@ -99,16 +99,16 @@ class Setting < ActiveRecord::Base
src = <<-END_SRC src = <<-END_SRC
def self.#{name} def self.#{name}
# when runnung too early, there is no settings table. do nothing # when runnung too early, there is no settings table. do nothing
self[:#{name}] if connection.table_exists?(table_name) self[:#{name}] if settings_table_exists_yet?
end end
def self.#{name}? def self.#{name}?
# when runnung too early, there is no settings table. do nothing # when runnung too early, there is no settings table. do nothing
self[:#{name}].to_i > 0 if connection.table_exists?(table_name) self[:#{name}].to_i > 0 if settings_table_exists_yet?
end end
def self.#{name}=(value) def self.#{name}=(value)
if connection.table_exists?(table_name) if settings_table_exists_yet?
self[:#{name}] = value self[:#{name}] = value
else else
logger.warn "Trying to save a setting named '#{name}' while there is no 'setting' table yet. This setting will not be saved!" logger.warn "Trying to save a setting named '#{name}' while there is no 'setting' table yet. This setting will not be saved!"
@ -222,4 +222,13 @@ private
def self.base_cache_key(name, timestamp) def self.base_cache_key(name, timestamp)
"/openproject/settings/#{timestamp}/#{name}" "/openproject/settings/#{timestamp}/#{name}"
end end
def self.settings_table_exists_yet?
# Check whether the settings table already exists. This makes plugins
# patching core classes not break things when settings are accessed.
# I'm not sure this is a good idea, but that's the way it is right now,
# and caching this improves performance significantly for actions
# accessing settings a lot.
@settings_table_exists_yet ||= connection.table_exists?(table_name)
end
end end

@ -38,6 +38,7 @@ See doc/COPYRIGHT.rdoc for more details.
* `#2708` Fix: API key auth does not work for custom_field actions * `#2708` Fix: API key auth does not work for custom_field actions
* `#2716` Fix: Repository is not auto-created when activated in project settings * `#2716` Fix: Repository is not auto-created when activated in project settings
* `#2717` Fix: Multiple journal entries when adding multiple attachments in one change * `#2717` Fix: Multiple journal entries when adding multiple attachments in one change
* Improve settings performance by caching whether the settings table exists
## 3.0.0pre27 ## 3.0.0pre27

Loading…
Cancel
Save