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:
David Taylor
2020-05-29 13:04:51 +01:00
committed by GitHub
parent 7635c18a14
commit d29d69e10d
3 changed files with 36 additions and 18 deletions

View File

@@ -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