mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Eradicate N+1 queries from the theme admin page
This commit is contained in:
@@ -16,10 +16,12 @@ class Theme < ActiveRecord::Base
|
||||
has_many :theme_fields, dependent: :destroy
|
||||
has_many :theme_settings, dependent: :destroy
|
||||
has_many :child_theme_relation, class_name: 'ChildTheme', foreign_key: 'parent_theme_id', dependent: :destroy
|
||||
has_many :child_themes, through: :child_theme_relation, source: :child_theme
|
||||
has_many :child_themes, -> { order(:name) }, through: :child_theme_relation, source: :child_theme
|
||||
has_many :color_schemes
|
||||
belongs_to :remote_theme
|
||||
|
||||
has_one :settings_field, -> { where(target_id: Theme.targets[:settings], name: "yaml") }, class_name: 'ThemeField'
|
||||
|
||||
validate :component_validations
|
||||
|
||||
scope :user_selectable, ->() {
|
||||
@@ -346,7 +348,7 @@ class Theme < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def settings
|
||||
field = theme_fields.where(target_id: Theme.targets[:settings], name: "yaml").first
|
||||
field = settings_field
|
||||
return [] unless field && field.error.nil?
|
||||
|
||||
settings = []
|
||||
|
||||
@@ -9,6 +9,7 @@ class ThemeSetting < ActiveRecord::Base
|
||||
theme.clear_cached_settings!
|
||||
theme.remove_from_cache!
|
||||
theme.theme_fields.update_all(value_baked: nil)
|
||||
theme.theme_settings.reload
|
||||
SvgSprite.expire_cache if self.name.to_s.include?("_icon")
|
||||
CSP::Extension.clear_theme_extensions_cache! if name.to_s == CSP::Extension::THEME_SETTING
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user