mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Remove N+1s from ThemeController#update and #show (#12842)
These endpoints only return one `Theme` row, but the one-many relations were not being preloaded efficiently. This commit moves the `includes` statement to a scope, and makes use of it in `#index`, `#show`, and `#update`.
This commit is contained in:
@@ -38,6 +38,19 @@ class Theme < ActiveRecord::Base
|
||||
where('user_selectable OR id = ?', SiteSetting.default_theme_id)
|
||||
}
|
||||
|
||||
scope :include_relations, -> {
|
||||
includes(:child_themes,
|
||||
:parent_themes,
|
||||
:remote_theme,
|
||||
:theme_settings,
|
||||
:settings_field,
|
||||
:locale_fields,
|
||||
:user,
|
||||
:color_scheme,
|
||||
theme_fields: :upload
|
||||
)
|
||||
}
|
||||
|
||||
def notify_color_change(color, scheme: nil)
|
||||
scheme ||= color.color_scheme
|
||||
changed_colors << color if color
|
||||
|
||||
Reference in New Issue
Block a user