Monkey-patch Sprockets to prevent cache ballooning
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
9734232530
commit
31fc5965ba
2 changed files with 25 additions and 0 deletions
3
config/initializers/sprockets_base_file_digest_key.rb
Normal file
3
config/initializers/sprockets_base_file_digest_key.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Sprockets::Base.prepend(Gitlab::Patch::SprocketsBaseFileDigestKey)
|
22
lib/gitlab/patch/sprockets_base_file_digest_key.rb
Normal file
22
lib/gitlab/patch/sprockets_base_file_digest_key.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# This monkey patch prevent cache ballooning when caching tmp/cache/assets/sprockets
|
||||
# on the CI. See https://github.com/rails/sprockets/issues/563 and
|
||||
# https://github.com/rails/sprockets/compare/3.x...jmreid:no-mtime-for-digest-key.
|
||||
module Gitlab
|
||||
module Patch
|
||||
module SprocketsBaseFileDigestKey
|
||||
def file_digest(path)
|
||||
if stat = self.stat(path)
|
||||
digest = self.stat_digest(path, stat)
|
||||
integrity_uri = self.hexdigest_integrity_uri(digest)
|
||||
|
||||
key = Sprockets::UnloadedAsset.new(path, self).file_digest_key(integrity_uri)
|
||||
cache.fetch(key) do
|
||||
digest
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue