Speed up `all_commit_shas` for new merge requests
For merge requests created after 9.4, we have a `merge_request_diff_commits` table we can get all the SHAs from very quickly. We just need to exclude these when we load from the legacy format, by ignoring diffs with no serialised commits. Once these have been migrated in the background, every MR will see this improvement.
This commit is contained in:
parent
d40445e4c9
commit
4c0864fd9e
|
@ -849,7 +849,10 @@ class MergeRequest < ActiveRecord::Base
|
||||||
#
|
#
|
||||||
def all_commit_shas
|
def all_commit_shas
|
||||||
if persisted?
|
if persisted?
|
||||||
merge_request_diffs.preload(:merge_request_diff_commits).flat_map(&:commit_shas).uniq
|
column_shas = MergeRequestDiffCommit.where(merge_request_diff: merge_request_diffs).pluck('DISTINCT(sha)')
|
||||||
|
serialised_shas = merge_request_diffs.where.not(st_commits: nil).flat_map(&:commit_shas)
|
||||||
|
|
||||||
|
(column_shas + serialised_shas).uniq
|
||||||
elsif compare_commits
|
elsif compare_commits
|
||||||
compare_commits.to_a.reverse.map(&:id)
|
compare_commits.to_a.reverse.map(&:id)
|
||||||
else
|
else
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
title: Make loading new merge requests (those created after the 9.4 upgrade) faster
|
||||||
|
merge_request:
|
||||||
|
author:
|
|
@ -803,7 +803,7 @@ describe MergeRequest, models: true do
|
||||||
shared_examples 'returning all SHA' do
|
shared_examples 'returning all SHA' do
|
||||||
it 'returns all SHA from all merge_request_diffs' do
|
it 'returns all SHA from all merge_request_diffs' do
|
||||||
expect(subject.merge_request_diffs.size).to eq(2)
|
expect(subject.merge_request_diffs.size).to eq(2)
|
||||||
expect(subject.all_commit_shas).to eq(all_commit_shas)
|
expect(subject.all_commit_shas).to match_array(all_commit_shas)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue