mirror of
https://github.com/discourse/discourse.git
synced 2025-02-22 04:07:27 +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
|
end
|
||||||
|
|
||||||
attr_accessor :is_base
|
attr_accessor :is_base
|
||||||
|
attr_accessor :skip_publish
|
||||||
|
|
||||||
has_many :color_scheme_colors, -> { order('id ASC') }, dependent: :destroy
|
has_many :color_scheme_colors, -> { order('id ASC') }, dependent: :destroy
|
||||||
|
|
||||||
alias_method :colors, :color_scheme_colors
|
alias_method :colors, :color_scheme_colors
|
||||||
|
|
||||||
before_save :bump_version
|
before_save :bump_version
|
||||||
after_save :publish_discourse_stylesheet
|
after_save_commit :publish_discourse_stylesheet, unless: :skip_publish
|
||||||
after_save :dump_caches
|
after_save_commit :dump_caches
|
||||||
after_destroy :dump_caches
|
after_destroy :dump_caches
|
||||||
belongs_to :theme
|
belongs_to :theme
|
||||||
|
|
||||||
@ -241,6 +242,7 @@ class ColorScheme < ActiveRecord::Base
|
|||||||
end if params[:colors]
|
end if params[:colors]
|
||||||
|
|
||||||
new_color_scheme.colors = colors
|
new_color_scheme.colors = colors
|
||||||
|
new_color_scheme.skip_publish if params[:skip_publish]
|
||||||
new_color_scheme.save
|
new_color_scheme.save
|
||||||
new_color_scheme
|
new_color_scheme
|
||||||
end
|
end
|
||||||
@ -303,18 +305,27 @@ class ColorScheme < ActiveRecord::Base
|
|||||||
|
|
||||||
def publish_discourse_stylesheet
|
def publish_discourse_stylesheet
|
||||||
if self.id
|
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)
|
def self.publish_discourse_stylesheets!(id = nil)
|
||||||
if theme_ids.present?
|
Stylesheet::Manager.clear_color_scheme_cache!
|
||||||
Stylesheet::Manager.cache.clear
|
|
||||||
Theme.notify_theme_change(
|
theme_ids = []
|
||||||
theme_ids,
|
if id
|
||||||
with_scheme: true,
|
theme_ids = Theme.where(color_scheme_id: id).pluck(:id)
|
||||||
clear_manager_cache: false,
|
else
|
||||||
all_themes: true
|
theme_ids = Theme.all.pluck(:id)
|
||||||
)
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user