diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 21:08:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 21:08:44 +0300 |
commit | 61b943c213065636abd4ebb34a3fba5412aa047f (patch) | |
tree | 45bd34aebd141823116ff91b97720c2daedf4814 /lib/gitlab | |
parent | 93b6ee78bf98cbc42712b7c5486ab0e78adb339f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/diff/highlight_cache.rb | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/gitlab/diff/highlight_cache.rb b/lib/gitlab/diff/highlight_cache.rb index 8e9dc3a305f..88f396fa7b9 100644 --- a/lib/gitlab/diff/highlight_cache.rb +++ b/lib/gitlab/diff/highlight_cache.rb @@ -6,7 +6,8 @@ module Gitlab include Gitlab::Utils::Gzip include Gitlab::Utils::StrongMemoize - EXPIRATION = 1.week + EXPIRATION = 1.day + PREVIOUS_EXPIRATION_PERIOD = 7.days VERSION = 2 delegate :diffable, to: :@diff_collection @@ -69,19 +70,33 @@ module Gitlab def key strong_memoize(:redis_key) do - [ - 'highlighted-diff-files', - diffable.cache_key, - VERSION, + options = [ diff_options, Feature.enabled?(:use_marker_ranges, diffable.project), Feature.enabled?(:diff_line_syntax_highlighting, diffable.project) - ].join(":") + ] + + options_for_key = + if Feature.enabled?(:highlight_diffs_optimize_memory_usage, diffable.project) + [OpenSSL::Digest::SHA256.hexdigest(options.join)] + else + options + end + + ['highlighted-diff-files', diffable.cache_key, VERSION, *options_for_key].join(":") end end private + def expiration_period + if Feature.enabled?(:highlight_diffs_optimize_memory_usage, diffable.project) + EXPIRATION + else + PREVIOUS_EXPIRATION_PERIOD + end + end + def set_highlighted_diff_lines(diff_file, content) diff_file.highlighted_diff_lines = content.map do |line| Gitlab::Diff::Line.safe_init_from_hash(line) @@ -138,7 +153,7 @@ module Gitlab # HSETs have to have their expiration date manually updated # - redis.expire(key, EXPIRATION) + redis.expire(key, expiration_period) end record_memory_usage(fetch_memory_usage(redis, key)) |