mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 03:19:10 +00:00
Color scheme optional defer publish (#12972)
* DEV: add a method of skipping publishing stylesheets afer color scheme save allows a method to publish all stylesheets if we make changes to many stylesheets at once * use after_save_commit for stylesheet change callbacks This may be more reliable for picking up new stylesheet changes via messagebus as after_save does not guarantee the updates exists in the DB yet. * add skip_publish option for create_from_base
This commit is contained in:
parent
05ac4f4091
commit
11fe13b45e
@ -155,14 +155,15 @@ class ColorScheme < ActiveRecord::Base
|
||||
end
|
||||
|
||||
attr_accessor :is_base
|
||||
attr_accessor :skip_publish
|
||||
|
||||
has_many :color_scheme_colors, -> { order('id ASC') }, dependent: :destroy
|
||||
|
||||
alias_method :colors, :color_scheme_colors
|
||||
|
||||
before_save :bump_version
|
||||
after_save :publish_discourse_stylesheet
|
||||
after_save :dump_caches
|
||||
after_save_commit :publish_discourse_stylesheet, unless: :skip_publish
|
||||
after_save_commit :dump_caches
|
||||
after_destroy :dump_caches
|
||||
belongs_to :theme
|
||||
|
||||
@ -241,6 +242,7 @@ class ColorScheme < ActiveRecord::Base
|
||||
end if params[:colors]
|
||||
|
||||
new_color_scheme.colors = colors
|
||||
new_color_scheme.skip_publish if params[:skip_publish]
|
||||
new_color_scheme.save
|
||||
new_color_scheme
|
||||
end
|
||||
@ -303,18 +305,27 @@ class ColorScheme < ActiveRecord::Base
|
||||
|
||||
def publish_discourse_stylesheet
|
||||
if self.id
|
||||
Stylesheet::Manager.clear_color_scheme_cache!
|
||||
self.class.publish_discourse_stylesheets!(self.id)
|
||||
end
|
||||
end
|
||||
|
||||
theme_ids = Theme.where(color_scheme_id: self.id).pluck(:id)
|
||||
if theme_ids.present?
|
||||
Stylesheet::Manager.cache.clear
|
||||
Theme.notify_theme_change(
|
||||
theme_ids,
|
||||
with_scheme: true,
|
||||
clear_manager_cache: false,
|
||||
all_themes: true
|
||||
)
|
||||
end
|
||||
def self.publish_discourse_stylesheets!(id = nil)
|
||||
Stylesheet::Manager.clear_color_scheme_cache!
|
||||
|
||||
theme_ids = []
|
||||
if id
|
||||
theme_ids = Theme.where(color_scheme_id: id).pluck(:id)
|
||||
else
|
||||
theme_ids = Theme.all.pluck(:id)
|
||||
end
|
||||
if theme_ids.present?
|
||||
Stylesheet::Manager.cache.clear
|
||||
Theme.notify_theme_change(
|
||||
theme_ids,
|
||||
with_scheme: true,
|
||||
clear_manager_cache: false,
|
||||
all_themes: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user