Commit 2deb97ad authored by Sean McGivern's avatar Sean McGivern

Merge branch '48246-osw-load-diffs-improvement' into 'master'

Filter diff files by given path on DB instead Ruby

See merge request gitlab-org/gitlab-ce!20940
parents 0233fffe fc4a0cd0
...@@ -249,15 +249,13 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -249,15 +249,13 @@ class MergeRequestDiff < ActiveRecord::Base
end end
def load_diffs(options) def load_diffs(options)
raw = merge_request_diff_files.map(&:to_hash) collection = merge_request_diff_files
if paths = options[:paths] if paths = options[:paths]
raw = raw.select do |diff| collection = collection.where('old_path IN (?) OR new_path IN (?)', paths, paths)
paths.include?(diff[:old_path]) || paths.include?(diff[:new_path])
end
end end
Gitlab::Git::DiffCollection.new(raw, options) Gitlab::Git::DiffCollection.new(collection.map(&:to_hash), options)
end end
def load_commits def load_commits
......
---
title: Improve performance when fetching collapsed diffs and commenting in merge requests
merge_request: 20940
author:
type: performance
...@@ -127,6 +127,13 @@ describe MergeRequestDiff do ...@@ -127,6 +127,13 @@ describe MergeRequestDiff do
expect(diffs.map(&:new_path)).to contain_exactly('files/ruby/popen.rb') expect(diffs.map(&:new_path)).to contain_exactly('files/ruby/popen.rb')
end end
it 'only serializes diff files found by query' do
expect(diff_with_commits.merge_request_diff_files.count).to be > 10
expect_any_instance_of(MergeRequestDiffFile).to receive(:to_hash).once
diffs
end
it 'uses the diffs from the DB' do it 'uses the diffs from the DB' do
expect(diff_with_commits).to receive(:load_diffs) expect(diff_with_commits).to receive(:load_diffs)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment