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:
David Taylor 2022-02-18 22:30:20 +00:00
parent 8e86d8a5dd
commit 51afa579f7
4 changed files with 3 additions and 14 deletions

View File

@ -91,7 +91,6 @@ class Theme < ActiveRecord::Base
update_javascript_cache!
remove_from_cache!
clear_cached_settings!
DB.after_commit { ColorScheme.hex_cache.clear }
notify_theme_change(with_scheme: notify_with_scheme)
@ -135,7 +134,6 @@ class Theme < ActiveRecord::Base
after_destroy do
remove_from_cache!
clear_cached_settings!
if SiteSetting.default_theme_id == self.id
Theme.clear_default!
end
@ -529,13 +527,13 @@ class Theme < ActiveRecord::Base
end
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
end
end
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 = {}
self.settings.each do |setting|
settings_hash[setting.name] = setting.default
@ -561,13 +559,6 @@ class Theme < ActiveRecord::Base
hash
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
hash = {}

View File

@ -378,7 +378,6 @@ class ThemeField < ActiveRecord::Base
DB.after_commit { Stylesheet::Manager.clear_theme_cache! }
elsif settings_field?
validate_yaml!
theme.clear_cached_settings!
DB.after_commit { CSP::Extension.clear_theme_extensions_cache! }
DB.after_commit { SvgSprite.expire_cache }
self.value_baked = "baked"

View File

@ -5,7 +5,6 @@ class ThemeTranslationOverride < ActiveRecord::Base
after_commit do
theme.theme_fields.where(target_id: Theme.targets[:translations]).update_all(value_baked: nil)
theme.clear_cached_settings!
theme.remove_from_cache!
end
end

View File

@ -512,7 +512,7 @@ HTML
theme.save!
Upload.find(upload.id).destroy
theme.clear_cached_settings!
theme.remove_from_cache!
json = JSON.parse(cached_settings(theme.id))
expect(json).to be_empty