A platform for community discussion. Free, open, simple.
PERF: Avoid re-compiling system themes during db:seed (#40124)
David Taylor245a10ad7145
diff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rbindex 0e083064391..0db7d1bbb83 100644--- a/app/models/remote_theme.rb+++ b/app/models/remote_theme.rb@@ -87,13 +87,15 @@ class RemoteTheme < ActiveRecord::Basedef self.import_theme_from_directory(directory,theme_id: nil,- allow_out_of_sequence_migration: false+ allow_out_of_sequence_migration: false,+ before_save: nil)update_theme(ThemeStore::DirectoryImporter.new(directory),update_components: "none",theme_id: theme_id,allow_out_of_sequence_migration: allow_out_of_sequence_migration,+ before_save: before_save,)end@@ -103,7 +105,8 @@ class RemoteTheme < ActiveRecord::Basetheme_id: nil,update_components: nil,run_migrations: true,- allow_out_of_sequence_migration: false+ allow_out_of_sequence_migration: false,+ before_save: nil)importer.import!@@ -139,6 +142,7 @@ class RemoteTheme < ActiveRecord::Basealready_in_transaction: true,run_migrations:,allow_out_of_sequence_migration:,+ before_save: before_save,)if existing && update_components.present? && update_components != "none"@@ -244,7 +248,8 @@ class RemoteTheme < ActiveRecord::Baseraise_if_theme_save_fails: true,already_in_transaction: false,run_migrations: true,- allow_out_of_sequence_migration: false+ allow_out_of_sequence_migration: false,+ before_save: nil)cleanup = false@@ -390,6 +395,8 @@ class RemoteTheme < ActiveRecord::Baseself.save!+ before_save&.call(theme)+if raise_if_theme_save_failstheme.save!elsediff --git a/lib/system_themes_manager.rb b/lib/system_themes_manager.rbindex bb5f28c7bc2..31f3906d3a7 100644--- a/lib/system_themes_manager.rb+++ b/lib/system_themes_manager.rb@@ -13,21 +13,20 @@ class SystemThemesManageris_initial_install = !Theme.exists?(id: theme_id)+ before_save =+ if is_initial_install && theme_id == Theme::CORE_THEMES["horizon"]+ ->(t) { t.dark_color_scheme = t.color_schemes.find { |s| s.name == "Horizon Dark" } }+ end+theme =RemoteTheme.import_theme_from_directory(theme_dir,theme_id: theme_id,allow_out_of_sequence_migration: !is_initial_install,+ before_save: before_save,)- theme.update_column(:enabled, true)-- if is_initial_install- if theme_id == Theme::CORE_THEMES["horizon"]- theme.update!(dark_color_scheme: theme.color_schemes.find_by(name: "Horizon Dark"))- end- end- theme.save!+ theme.update_column(:enabled, true) unless theme.enabled?Stylesheet::Manager.clear_theme_cache!end