summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-03-09 16:41:28 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-03-09 16:41:28 +0000
commit0dea3dc85117e7fccfb36e31bdb5dd6cedb5dbad (patch)
treeaadf2975e31e462f0c94cc4d46956ecaaa93b2dc /lib
parent3bbe60f8e802ce3d9da060a47b7f635dedba7370 (diff)
parentea81c27612386e1e6db3b95731c2f8fe6f1bc149 (diff)
downloadgitlab-ce-0dea3dc85117e7fccfb36e31bdb5dd6cedb5dbad.tar.gz
Merge branch 'osw-43951-single-batch-blob-request-to-gitaly' into 'master'
Submit a single batch blob RPC to Gitaly per HTTP request when viewing diffs Closes #43951 See merge request gitlab-org/gitlab-ce!17659
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/diff/file_collection/merge_request_diff.rb18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/gitlab/diff/file_collection/merge_request_diff.rb b/lib/gitlab/diff/file_collection/merge_request_diff.rb
index fcda1fe2233..ff68bc7303a 100644
--- a/lib/gitlab/diff/file_collection/merge_request_diff.rb
+++ b/lib/gitlab/diff/file_collection/merge_request_diff.rb
@@ -13,7 +13,16 @@ module Gitlab
end
def diff_files
- super.tap { |_| store_highlight_cache }
+ # Make sure to _not_ send any method call to Gitlab::Diff::File
+ # _before_ all of them were collected (`super`). Premature method calls will
+ # trigger N+1 RPCs to Gitaly through BatchLoader records (Blob.lazy).
+ #
+ diff_files = super
+
+ diff_files.each { |diff_file| cache_highlight!(diff_file) if cacheable?(diff_file) }
+ store_highlight_cache
+
+ diff_files
end
def real_size
@@ -22,13 +31,6 @@ module Gitlab
private
- # Extracted method to highlight in the same iteration to the diff_collection.
- def decorate_diff!(diff)
- diff_file = super
- cache_highlight!(diff_file) if cacheable?(diff_file)
- diff_file
- end
-
def highlight_diff_file_from_cache!(diff_file, cache_diff_lines)
diff_file.highlighted_diff_lines = cache_diff_lines.map do |line|
Gitlab::Diff::Line.init_from_hash(line)