summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-07-07 12:56:09 +0100
committerSean McGivern <sean@gitlab.com>2017-07-07 13:03:36 +0100
commit412daefddaac4642c4d7e9c9e6b34132e661d885 (patch)
treee0ae5e82e4b0e3b285d21463f617495890116cb4
parentd40445e4c9964ae0ab793bfdd7ba530de4259716 (diff)
downloadgitlab-ce-speed-up-merge-request-all-commits-shas.tar.gz
Speed up `all_commit_shas` for new merge requestsspeed-up-merge-request-all-commits-shas
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.
-rw-r--r--app/models/merge_request.rb5
-rw-r--r--changelogs/unreleased/speed-up-merge-request-all-commits-shas.yml4
2 files changed, 8 insertions, 1 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 2fc6191e785..6ea774470af 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -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
diff --git a/changelogs/unreleased/speed-up-merge-request-all-commits-shas.yml b/changelogs/unreleased/speed-up-merge-request-all-commits-shas.yml
new file mode 100644
index 00000000000..00f55edc2b7
--- /dev/null
+++ b/changelogs/unreleased/speed-up-merge-request-all-commits-shas.yml
@@ -0,0 +1,4 @@
+---
+title: Make loading new merge requests (those created after the 9.4 upgrade) faster
+merge_request:
+author: