summaryrefslogtreecommitdiff
path: root/lib/gitlab/patch/sprockets_base_file_digest_key.rb
blob: 3925cdbbadaffe91356ab8e824801a7fcba4104c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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