diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 03:11:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 03:11:02 +0300 |
commit | c95fc172145f1bdbc8d959b6cee31555fc545784 (patch) | |
tree | 5aa4940ddefb9bea164905d61916593cc265a05c /lib/gitlab/diff | |
parent | eda321fc0b96e44e296341f6288dd7f1a27ba93a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/diff')
-rw-r--r-- | lib/gitlab/diff/highlight_cache.rb | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/gitlab/diff/highlight_cache.rb b/lib/gitlab/diff/highlight_cache.rb index 7cfe0086f57..44e3e9987f7 100644 --- a/lib/gitlab/diff/highlight_cache.rb +++ b/lib/gitlab/diff/highlight_cache.rb @@ -6,7 +6,7 @@ module Gitlab include Gitlab::Utils::Gzip include Gitlab::Utils::StrongMemoize - EXPIRATION = 1.day + EXPIRATION = 1.hour VERSION = 2 delegate :diffable, to: :@diff_collection @@ -82,6 +82,16 @@ module Gitlab private + def expiration + return 1.day unless Feature.enabled?(:highlight_diffs_renewable_expiration, diffable.project) + + if Feature.enabled?(:highlight_diffs_short_renewable_expiration, diffable.project) + EXPIRATION + else + 8.hours + 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) @@ -137,8 +147,7 @@ module Gitlab end # HSETs have to have their expiration date manually updated - # - redis.expire(key, EXPIRATION) + redis.expire(key, expiration) end record_memory_usage(fetch_memory_usage(redis, key)) @@ -188,11 +197,19 @@ module Gitlab return {} unless file_paths.any? results = [] + cache_key = key + highlight_diffs_renewable_expiration_enabled = Feature.enabled?(:highlight_diffs_renewable_expiration, diffable.project) + expiration_period = expiration Gitlab::Redis::Cache.with do |redis| - results = redis.hmget(key, file_paths) + redis.pipelined do + results = redis.hmget(cache_key, file_paths) + redis.expire(key, expiration_period) if highlight_diffs_renewable_expiration_enabled + end end + results = results.value + record_hit_ratio(results) results.map! do |result| |