BigW Consortium Gitlab

Commit 4c0864fd by Sean McGivern

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.
parent d40445e4
......@@ -849,7 +849,10 @@ class MergeRequest < ActiveRecord::Base
#
def all_commit_shas
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
compare_commits.to_a.reverse.map(&:id)
else
......
---
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
it 'returns all SHA from all merge_request_diffs' do
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
......
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