PERF: Eradicate N+1 queries from the theme admin page

This commit is contained in:
David Taylor
2018-12-20 17:13:05 +00:00
committed by Sam
parent 2909e7fbdf
commit 7feabd9e49
6 changed files with 34 additions and 7 deletions

View File

@@ -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 = []

View File

@@ -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