mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Invalidate database theme cache when hostname changes (#9908)
Hostname can vary per-site on a multisite cluster, so this change requires converting the compiler_version from a constant into a class method which is evaluated at runtime. The value is stored in the theme DistributedCache, so performance impact should be negligible.
This commit is contained in:
@@ -716,7 +716,7 @@ HTML
|
||||
first_common_value = Theme.lookup_field(child.id, :desktop, "header")
|
||||
first_extra_js_value = Theme.lookup_field(child.id, :extra_js, nil)
|
||||
|
||||
stub_const(ThemeField, :COMPILER_VERSION, "SOME_NEW_HASH") do
|
||||
Theme.stubs(:compiler_version).returns("SOME_NEW_HASH") do
|
||||
second_common_value = Theme.lookup_field(child.id, :desktop, "header")
|
||||
second_extra_js_value = Theme.lookup_field(child.id, :extra_js, nil)
|
||||
|
||||
@@ -730,5 +730,18 @@ HTML
|
||||
expect(new_extra_js_compiler_version).to eq("SOME_NEW_HASH")
|
||||
end
|
||||
end
|
||||
|
||||
it 'recompiles when the hostname changes' do
|
||||
theme.set_field(target: :settings, name: :yaml, value: "name: bob")
|
||||
theme_field = theme.set_field(target: :common, name: :after_header, value: '<script>console.log("hello world");</script>')
|
||||
theme.save!
|
||||
|
||||
expect(Theme.lookup_field(theme.id, :common, :after_header)).to include("_ws=#{Discourse.current_hostname}")
|
||||
|
||||
SiteSetting.force_hostname = "someotherhostname.com"
|
||||
Theme.clear_cache!
|
||||
|
||||
expect(Theme.lookup_field(theme.id, :common, :after_header)).to include("_ws=someotherhostname.com")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user