DEV: Use the theme cache helper for settings
The previous Discourse.cache usage was different to how other theme-related caching is handled, and also requires reaching out to redis every time. The common theme cache is held in memory (as a DistributedCache)
This commit is contained in:
parent
8e86d8a5dd
commit
51afa579f7
|
@ -91,7 +91,6 @@ class Theme < ActiveRecord::Base
|
||||||
update_javascript_cache!
|
update_javascript_cache!
|
||||||
|
|
||||||
remove_from_cache!
|
remove_from_cache!
|
||||||
clear_cached_settings!
|
|
||||||
DB.after_commit { ColorScheme.hex_cache.clear }
|
DB.after_commit { ColorScheme.hex_cache.clear }
|
||||||
notify_theme_change(with_scheme: notify_with_scheme)
|
notify_theme_change(with_scheme: notify_with_scheme)
|
||||||
|
|
||||||
|
@ -135,7 +134,6 @@ class Theme < ActiveRecord::Base
|
||||||
|
|
||||||
after_destroy do
|
after_destroy do
|
||||||
remove_from_cache!
|
remove_from_cache!
|
||||||
clear_cached_settings!
|
|
||||||
if SiteSetting.default_theme_id == self.id
|
if SiteSetting.default_theme_id == self.id
|
||||||
Theme.clear_default!
|
Theme.clear_default!
|
||||||
end
|
end
|
||||||
|
@ -529,13 +527,13 @@ class Theme < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def cached_settings
|
def cached_settings
|
||||||
Discourse.cache.fetch("settings_for_theme_#{self.id}", expires_in: 30.minutes) do
|
Theme.get_set_cache "settings_for_theme_#{self.id}" do
|
||||||
build_settings_hash
|
build_settings_hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def cached_default_settings
|
def cached_default_settings
|
||||||
Discourse.cache.fetch("default_settings_for_theme_#{self.id}", expires_in: 30.minutes) do
|
Theme.get_set_cache "default_settings_for_theme_#{self.id}" do
|
||||||
settings_hash = {}
|
settings_hash = {}
|
||||||
self.settings.each do |setting|
|
self.settings.each do |setting|
|
||||||
settings_hash[setting.name] = setting.default
|
settings_hash[setting.name] = setting.default
|
||||||
|
@ -561,13 +559,6 @@ class Theme < ActiveRecord::Base
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_cached_settings!
|
|
||||||
DB.after_commit do
|
|
||||||
Discourse.cache.delete("settings_for_theme_#{self.id}")
|
|
||||||
Discourse.cache.delete("default_settings_for_theme_#{self.id}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def included_settings
|
def included_settings
|
||||||
hash = {}
|
hash = {}
|
||||||
|
|
||||||
|
|
|
@ -378,7 +378,6 @@ class ThemeField < ActiveRecord::Base
|
||||||
DB.after_commit { Stylesheet::Manager.clear_theme_cache! }
|
DB.after_commit { Stylesheet::Manager.clear_theme_cache! }
|
||||||
elsif settings_field?
|
elsif settings_field?
|
||||||
validate_yaml!
|
validate_yaml!
|
||||||
theme.clear_cached_settings!
|
|
||||||
DB.after_commit { CSP::Extension.clear_theme_extensions_cache! }
|
DB.after_commit { CSP::Extension.clear_theme_extensions_cache! }
|
||||||
DB.after_commit { SvgSprite.expire_cache }
|
DB.after_commit { SvgSprite.expire_cache }
|
||||||
self.value_baked = "baked"
|
self.value_baked = "baked"
|
||||||
|
|
|
@ -5,7 +5,6 @@ class ThemeTranslationOverride < ActiveRecord::Base
|
||||||
|
|
||||||
after_commit do
|
after_commit do
|
||||||
theme.theme_fields.where(target_id: Theme.targets[:translations]).update_all(value_baked: nil)
|
theme.theme_fields.where(target_id: Theme.targets[:translations]).update_all(value_baked: nil)
|
||||||
theme.clear_cached_settings!
|
|
||||||
theme.remove_from_cache!
|
theme.remove_from_cache!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -512,7 +512,7 @@ HTML
|
||||||
theme.save!
|
theme.save!
|
||||||
|
|
||||||
Upload.find(upload.id).destroy
|
Upload.find(upload.id).destroy
|
||||||
theme.clear_cached_settings!
|
theme.remove_from_cache!
|
||||||
|
|
||||||
json = JSON.parse(cached_settings(theme.id))
|
json = JSON.parse(cached_settings(theme.id))
|
||||||
expect(json).to be_empty
|
expect(json).to be_empty
|
||||||
|
|
Loading…
Reference in New Issue