mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 04:55:46 +08:00
FIX: Correctly clear theme stylesheet cache when changing color scheme
This commit is contained in:
parent
54c2f24ee9
commit
e84531a6a6
@ -52,6 +52,7 @@ class Theme < ActiveRecord::Base
|
||||
changed_fields.clear
|
||||
|
||||
Theme.expire_site_cache! if saved_change_to_user_selectable? || saved_change_to_name?
|
||||
notify_with_scheme = saved_change_to_color_scheme_id?
|
||||
|
||||
reload
|
||||
settings_field&.ensure_baked! # Other fields require setting to be **baked**
|
||||
@ -60,6 +61,7 @@ class Theme < ActiveRecord::Base
|
||||
remove_from_cache!
|
||||
clear_cached_settings!
|
||||
ColorScheme.hex_cache.clear
|
||||
notify_theme_change(with_scheme: notify_with_scheme)
|
||||
end
|
||||
|
||||
after_destroy do
|
||||
@ -86,10 +88,6 @@ class Theme < ActiveRecord::Base
|
||||
SvgSprite.expire_cache
|
||||
end
|
||||
|
||||
after_commit ->(theme) do
|
||||
theme.notify_theme_change(with_scheme: theme.saved_change_to_color_scheme_id?)
|
||||
end, on: [:create, :update]
|
||||
|
||||
def self.get_set_cache(key, &blk)
|
||||
if val = @cache[key]
|
||||
return val
|
||||
|
@ -481,6 +481,31 @@ HTML
|
||||
expect(ColorScheme.hex_for_name('header_primary')).to eq('333333')
|
||||
end
|
||||
|
||||
it "correctly notifies about theme changes" do
|
||||
cs1 = Fabricate(:color_scheme)
|
||||
cs2 = Fabricate(:color_scheme)
|
||||
|
||||
theme = Fabricate(:theme,
|
||||
user_selectable: true,
|
||||
user: user,
|
||||
color_scheme_id: cs1.id
|
||||
)
|
||||
|
||||
messages = MessageBus.track_publish do
|
||||
theme.save!
|
||||
end.filter { |m| m.channel == "/file-change" }
|
||||
expect(messages.count).to eq(1)
|
||||
expect(messages.first.data.map { |d| d[:target] }).to contain_exactly(:desktop_theme, :mobile_theme)
|
||||
|
||||
# With color scheme change:
|
||||
messages = MessageBus.track_publish do
|
||||
theme.color_scheme_id = cs2.id
|
||||
theme.save!
|
||||
end.filter { |m| m.channel == "/file-change" }
|
||||
expect(messages.count).to eq(1)
|
||||
expect(messages.first.data.map { |d| d[:target] }).to contain_exactly(:admin, :desktop, :desktop_theme, :mobile, :mobile_theme)
|
||||
end
|
||||
|
||||
it 'handles settings cache correctly' do
|
||||
Theme.destroy_all
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user