Commit 1a3edcec authored by Douwe Maan's avatar Douwe Maan

Merge branch 'speed-up-merge-request-all-commits-shas' into 'master'

Speed up `all_commit_shas` for new merge requests

See merge request !12706
parents 4ccdb83a 4c0864fd
...@@ -849,7 +849,10 @@ class MergeRequest < ActiveRecord::Base ...@@ -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
......
---
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 ...@@ -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
......
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