summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2019-01-30 12:28:39 +0100
committerRémy Coutable <remy@rymai.me>2019-02-05 13:38:52 +0100
commit31fc5965baf9ca23a1da4a0ffc350102fe4c89c6 (patch)
tree92e8e5de086bb718f9c2fb7da9ac06384eaa549e
parent9734232530ceb2268d3e894b36ce7d5543c56e51 (diff)
downloadgitlab-ce-31fc5965baf9ca23a1da4a0ffc350102fe4c89c6.tar.gz
Monkey-patch Sprockets to prevent cache ballooning
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r--config/initializers/sprockets_base_file_digest_key.rb3
-rw-r--r--lib/gitlab/patch/sprockets_base_file_digest_key.rb22
2 files changed, 25 insertions, 0 deletions
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