mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
FIX: Invalidate stylesheet cache when discourse-fonts is bumped (#30869)
This commit is contained in:
@ -7,8 +7,12 @@ module Stylesheet
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Stylesheet::Manager
|
class Stylesheet::Manager
|
||||||
|
# Bump this number to invalidate all stylesheet caches (e.g. if you change something inside the compiler)
|
||||||
BASE_COMPILER_VERSION = 2
|
BASE_COMPILER_VERSION = 2
|
||||||
|
|
||||||
|
# Add any dependencies here which should automatically cause a global cache invalidation.
|
||||||
|
BASE_CACHE_KEY = "#{BASE_COMPILER_VERSION}::#{DiscourseFonts::VERSION}"
|
||||||
|
|
||||||
CACHE_PATH = "tmp/stylesheet-cache"
|
CACHE_PATH = "tmp/stylesheet-cache"
|
||||||
private_constant :CACHE_PATH
|
private_constant :CACHE_PATH
|
||||||
|
|
||||||
@ -132,13 +136,13 @@ class Stylesheet::Manager
|
|||||||
if File.exist?(manifest_full_path)
|
if File.exist?(manifest_full_path)
|
||||||
File.readlines(manifest_full_path, "r")[0]
|
File.readlines(manifest_full_path, "r")[0]
|
||||||
else
|
else
|
||||||
cachebuster = "#{BASE_COMPILER_VERSION}:#{fs_assets_hash}"
|
cachebuster = "#{BASE_CACHE_KEY}:#{fs_assets_hash}"
|
||||||
FileUtils.mkdir_p(MANIFEST_DIR)
|
FileUtils.mkdir_p(MANIFEST_DIR)
|
||||||
File.open(manifest_full_path, "w") { |f| f.print(cachebuster) }
|
File.open(manifest_full_path, "w") { |f| f.print(cachebuster) }
|
||||||
cachebuster
|
cachebuster
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
"#{BASE_COMPILER_VERSION}:#{max_file_mtime}"
|
"#{BASE_CACHE_KEY}:#{max_file_mtime}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1043,7 +1043,7 @@ RSpec.describe Stylesheet::Manager do
|
|||||||
|
|
||||||
describe ".fs_asset_cachebuster" do
|
describe ".fs_asset_cachebuster" do
|
||||||
it "returns a number in test/development mode" do
|
it "returns a number in test/development mode" do
|
||||||
expect(Stylesheet::Manager.fs_asset_cachebuster).to match(/\A[0-9]+:[0-9]+\z/)
|
expect(Stylesheet::Manager.fs_asset_cachebuster).to match(/\A.*:[0-9]+\z/)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with production mode enabled" do
|
context "with production mode enabled" do
|
||||||
@ -1056,7 +1056,7 @@ RSpec.describe Stylesheet::Manager do
|
|||||||
|
|
||||||
it "returns a hash" do
|
it "returns a hash" do
|
||||||
cachebuster = Stylesheet::Manager.fs_asset_cachebuster
|
cachebuster = Stylesheet::Manager.fs_asset_cachebuster
|
||||||
expect(cachebuster).to match(/\A[0-9]+:[0-9a-f]{40}\z/)
|
expect(cachebuster).to match(/\A.*:[0-9a-f]{40}\z/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "caches the value on the filesystem" do
|
it "caches the value on the filesystem" do
|
||||||
|
Reference in New Issue
Block a user