Skip to content

Sprockets caches files independent of content

This is a follow-up from: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/24542 and https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/25025.

It seems like at the moment Sprockets is always using the same caching key, no matter the content of a file. This is happening due to this line in our sprockets cache monkey patch. self.stat_digest is returning a string, but we are calling self.hexdigest_integrity_uri(digest) which expects a hexdigest. This call now always returns nil leading to the same cache key no matter of the content.

This caused the application.css not to be updated, independent of changes (see gitlab-ui#171 (closed)). I have verified that at least for SCSS the following patch fixes the problem:

diff --git a/lib/gitlab/patch/sprockets_base_file_digest_key.rb b/lib/gitlab/patch/sprockets_base_file_digest_key.rb
index 3925cdbbada..1c472638145 100644
--- a/lib/gitlab/patch/sprockets_base_file_digest_key.rb
+++ b/lib/gitlab/patch/sprockets_base_file_digest_key.rb
@@ -9,7 +9,7 @@ module Gitlab
       def file_digest(path)
         if stat = self.stat(path)
           digest = self.stat_digest(path, stat)
-          integrity_uri = self.hexdigest_integrity_uri(digest)
+          integrity_uri = self.integrity_uri(digest)

           key = Sprockets::UnloadedAsset.new(path, self).file_digest_key(integrity_uri)
           cache.fetch(key) do
Edited by Lukas Eipert