diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-03-08 23:46:05 -0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-03-08 23:46:05 -0300 |
commit | 7a9de8c557f967fdc5746259d1e082e4bb35ed9a (patch) | |
tree | 81580bf0145d739d52a2c39c5b59172c26a6ef91 | |
parent | cb5cc14dc41f75363dc36264ccd660895f7444e1 (diff) | |
download | gitlab-ce-osw-43951-single-batch-blob-request-to-gitaly.tar.gz |
Submit a single batch blob RPC to Gitaly per HTTP request when viewing diffsosw-43951-single-batch-blob-request-to-gitaly
-rw-r--r-- | changelogs/unreleased/osw-43951-single-batch-blob-request-to-gitaly.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/diff/file_collection/merge_request_diff.rb | 16 |
2 files changed, 13 insertions, 8 deletions
diff --git a/changelogs/unreleased/osw-43951-single-batch-blob-request-to-gitaly.yml b/changelogs/unreleased/osw-43951-single-batch-blob-request-to-gitaly.yml new file mode 100644 index 00000000000..34f834298b6 --- /dev/null +++ b/changelogs/unreleased/osw-43951-single-batch-blob-request-to-gitaly.yml @@ -0,0 +1,5 @@ +--- +title: Submit a single batch blob RPC to Gitaly per HTTP request when viewing diffs +merge_request: +author: +type: performance diff --git a/lib/gitlab/diff/file_collection/merge_request_diff.rb b/lib/gitlab/diff/file_collection/merge_request_diff.rb index fcda1fe2233..dfed3e1db36 100644 --- a/lib/gitlab/diff/file_collection/merge_request_diff.rb +++ b/lib/gitlab/diff/file_collection/merge_request_diff.rb @@ -13,7 +13,14 @@ 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) } + + diff_files.tap { |_| store_highlight_cache } end def real_size @@ -22,13 +29,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) |