diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-30 03:08:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-30 03:08:50 +0000 |
commit | 1d388ed855838a2d50588c131f9f23815f148344 (patch) | |
tree | d9278b42419b6a91c90aa4940c69684077d34273 /lib/gitlab/diff | |
parent | c36e59283ebcfd75281a9dda227ed060eeb5fbe7 (diff) | |
download | gitlab-ce-1d388ed855838a2d50588c131f9f23815f148344.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/diff')
-rw-r--r-- | lib/gitlab/diff/deprecated_highlight_cache.rb | 68 | ||||
-rw-r--r-- | lib/gitlab/diff/highlight_cache.rb | 15 |
2 files changed, 0 insertions, 83 deletions
diff --git a/lib/gitlab/diff/deprecated_highlight_cache.rb b/lib/gitlab/diff/deprecated_highlight_cache.rb deleted file mode 100644 index 47347686973..00000000000 --- a/lib/gitlab/diff/deprecated_highlight_cache.rb +++ /dev/null @@ -1,68 +0,0 @@ -# frozen_string_literal: true -# -module Gitlab - module Diff - class DeprecatedHighlightCache - delegate :diffable, to: :@diff_collection - delegate :diff_options, to: :@diff_collection - - def initialize(diff_collection, backend: Rails.cache) - @backend = backend - @diff_collection = diff_collection - end - - # - Reads from cache - # - Assigns DiffFile#highlighted_diff_lines for cached files - def decorate(diff_file) - if content = read_file(diff_file) - diff_file.highlighted_diff_lines = content.map do |line| - Gitlab::Diff::Line.init_from_hash(line) - end - end - end - - # It populates a Hash in order to submit a single write to the memory - # cache. This avoids excessive IO generated by N+1's (1 writing for - # each highlighted line or file). - def write_if_empty - return if cached_content.present? - - @diff_collection.diff_files.each do |diff_file| - next unless cacheable?(diff_file) - - diff_file_id = diff_file.file_identifier - - cached_content[diff_file_id] = diff_file.highlighted_diff_lines.map(&:to_hash) - end - - cache.write(key, cached_content, expires_in: 1.week) - end - - def clear - cache.delete(key) - end - - def key - [diffable, 'highlighted-diff-files', Gitlab::Diff::Line::SERIALIZE_KEYS, diff_options] - end - - private - - def read_file(diff_file) - cached_content[diff_file.file_identifier] - end - - def cache - @backend - end - - def cached_content - @cached_content ||= cache.read(key) || {} - end - - def cacheable?(diff_file) - diffable.present? && diff_file.text? && diff_file.diffable? - end - end - end -end diff --git a/lib/gitlab/diff/highlight_cache.rb b/lib/gitlab/diff/highlight_cache.rb index 403effbb0c6..a3d88664bac 100644 --- a/lib/gitlab/diff/highlight_cache.rb +++ b/lib/gitlab/diff/highlight_cache.rb @@ -57,17 +57,6 @@ module Gitlab private - # We create a Gitlab::Diff::DeprecatedHighlightCache here in order to - # expire deprecated cache entries while we make the transition. This can - # be removed when :hset_redis_diff_caching is fully launched. - # See https://gitlab.com/gitlab-org/gitlab/issues/38008 - # - def deprecated_cache - strong_memoize(:deprecated_cache) do - Gitlab::Diff::DeprecatedHighlightCache.new(@diff_collection) - end - end - def cacheable_files strong_memoize(:cacheable_files) do diff_files.select { |file| cacheable?(file) && read_file(file).nil? } @@ -104,10 +93,6 @@ module Gitlab # clear_memoization(:cached_content) clear_memoization(:cacheable_files) - - # Clean up any deprecated hash entries - # - deprecated_cache.clear end def file_paths |