use the cached plugin settings to determine if enabled

Change-Id: Idae91f14090fba31391ef10b8472114b606a0322
Reviewed-on: https://gerrit.instructure.com/25023
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2013-10-04 14:28:20 -06:00
parent 68d4bee5d9
commit 536f4d5038
2 changed files with 20 additions and 16 deletions

View File

@ -98,9 +98,16 @@ class PluginSetting < ActiveRecord::Base
read_attribute(:disabled) != true
end
def self.cached_plugin_setting(name)
plugin_setting = Rails.cache.fetch(settings_cache_key(name)) do
PluginSetting.find_by_name(name.to_s) || :nil
end
plugin_setting = nil if plugin_setting == :nil
plugin_setting
end
def self.settings_for_plugin(name, plugin=nil)
res = Rails.cache.fetch(settings_cache_key(name)) do
if (plugin_setting = PluginSetting.find_by_name(name.to_s)) && plugin_setting.valid_settings? && plugin_setting.enabled?
if (plugin_setting = cached_plugin_setting(name)) && plugin_setting.valid_settings? && plugin_setting.enabled?
plugin_setting.plugin = plugin
settings = plugin_setting.settings
else
@ -109,14 +116,11 @@ class PluginSetting < ActiveRecord::Base
settings = plugin.default_settings
end
settings || :nil
end
res = nil if res == :nil
res
settings
end
def self.settings_cache_key(name)
["settings_for_plugin", name].cache_key
["settings_for_plugin2", name].cache_key
end
def clear_cache

View File

@ -60,7 +60,7 @@ module Canvas
end
def enabled?
ps = PluginSetting.find_by_name(self.id.to_s)
ps = PluginSetting.cached_plugin_setting(self.id)
return false unless ps
ps.valid_settings? && ps.enabled?
end