From 31fc5965baf9ca23a1da4a0ffc350102fe4c89c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 30 Jan 2019 12:28:39 +0100 Subject: Monkey-patch Sprockets to prevent cache ballooning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- .../initializers/sprockets_base_file_digest_key.rb | 3 +++ lib/gitlab/patch/sprockets_base_file_digest_key.rb | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 config/initializers/sprockets_base_file_digest_key.rb create mode 100644 lib/gitlab/patch/sprockets_base_file_digest_key.rb diff --git a/config/initializers/sprockets_base_file_digest_key.rb b/config/initializers/sprockets_base_file_digest_key.rb new file mode 100644 index 00000000000..81ff3812091 --- /dev/null +++ b/config/initializers/sprockets_base_file_digest_key.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +Sprockets::Base.prepend(Gitlab::Patch::SprocketsBaseFileDigestKey) diff --git a/lib/gitlab/patch/sprockets_base_file_digest_key.rb b/lib/gitlab/patch/sprockets_base_file_digest_key.rb new file mode 100644 index 00000000000..3925cdbbada --- /dev/null +++ b/lib/gitlab/patch/sprockets_base_file_digest_key.rb @@ -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 -- cgit v1.2.3