Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-16 18:06:26 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-16 18:06:26 +0300
commit84727c8209a4412e21111a07f99b0438b03232de (patch)
tree1fcfa02b01548c3cdc561186870a1c807f227f0b /lib/gitlab/discussions_diff
parentd2798d607e11e0ebae83ae909404834388733428 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/discussions_diff')
-rw-r--r--lib/gitlab/discussions_diff/file_collection.rb29
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/gitlab/discussions_diff/file_collection.rb b/lib/gitlab/discussions_diff/file_collection.rb
index 4ab7314f509..6692dd76438 100644
--- a/lib/gitlab/discussions_diff/file_collection.rb
+++ b/lib/gitlab/discussions_diff/file_collection.rb
@@ -4,11 +4,16 @@ module Gitlab
module DiscussionsDiff
class FileCollection
include Gitlab::Utils::StrongMemoize
+ include Enumerable
def initialize(collection)
@collection = collection
end
+ def each(&block)
+ @collection.each(&block)
+ end
+
# Returns a Gitlab::Diff::File with the given ID (`unique_identifier` in
# Gitlab::Diff::File).
def find_by_id(id)
@@ -16,20 +21,12 @@ module Gitlab
end
# Writes cache and preloads highlighted diff lines for
- # object IDs, in @collection.
- #
- # highlightable_ids - Diff file `Array` responding to ID. The ID will be used
- # to generate the cache key.
+ # highlightable object IDs, in @collection.
#
# - Highlight cache is written just for uncached diff files
# - The cache content is not updated (there's no need to do so)
- def load_highlight(highlightable_ids)
- preload_highlighted_lines(highlightable_ids)
- end
-
- private
-
- def preload_highlighted_lines(ids)
+ def load_highlight
+ ids = highlightable_collection_ids
cached_content = read_cache(ids)
uncached_ids = ids.select.each_with_index { |_, i| cached_content[i].nil? }
@@ -46,6 +43,12 @@ module Gitlab
end
end
+ private
+
+ def highlightable_collection_ids
+ each.with_object([]) { |file, memo| memo << file.id unless file.resolved_at }
+ end
+
def read_cache(ids)
HighlightCache.read_multiple(ids)
end
@@ -57,9 +60,7 @@ module Gitlab
end
def diff_files
- strong_memoize(:diff_files) do
- @collection.map(&:raw_diff_file)
- end
+ strong_memoize(:diff_files) { map(&:raw_diff_file) }
end
# Processes the diff lines highlighting for diff files matching the given