summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-11-10 13:39:57 +0000
committerSean McGivern <sean@gitlab.com>2017-11-10 14:27:26 +0000
commitec73ecb0a88401932efc7b2b382db6905027b126 (patch)
treee5a62d984489c730fd4a099edaf655846ec43e22
parent65faebb95556809c5858347f1c24422505056827 (diff)
downloadgitlab-ce-ec73ecb0a88401932efc7b2b382db6905027b126.tar.gz
Fix another timeout when searching for pipelines
When we consider 'all' pipelines for MRs, we now mean: 1. The last 10,000 commits (unordered). 2. From the last 100 MR versions (newest first). This seems to fix the MRs that time out on GitLab.com.
-rw-r--r--app/models/merge_request.rb14
-rw-r--r--changelogs/unreleased/fix-502-mrs-with-lots-of-versions.yml6
2 files changed, 19 insertions, 1 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index efd8cca2947..dd4e67bc9da 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -865,7 +865,19 @@ class MergeRequest < ActiveRecord::Base
#
def all_commit_shas
if persisted?
- column_shas = MergeRequestDiffCommit.where(merge_request_diff: merge_request_diffs).limit(10_000).pluck('sha')
+ # MySQL doesn't support LIMIT in a subquery.
+ diffs_relation =
+ if Gitlab::Database.postgresql?
+ merge_request_diffs.order(id: :desc).limit(100)
+ else
+ merge_request_diffs
+ end
+
+ column_shas = MergeRequestDiffCommit
+ .where(merge_request_diff: diffs_relation)
+ .limit(10_000)
+ .pluck('sha')
+
serialised_shas = merge_request_diffs.where.not(st_commits: nil).flat_map(&:commit_shas)
(column_shas + serialised_shas).uniq
diff --git a/changelogs/unreleased/fix-502-mrs-with-lots-of-versions.yml b/changelogs/unreleased/fix-502-mrs-with-lots-of-versions.yml
new file mode 100644
index 00000000000..32cdfba4eec
--- /dev/null
+++ b/changelogs/unreleased/fix-502-mrs-with-lots-of-versions.yml
@@ -0,0 +1,6 @@
+---
+title: Ensure merge requests with lots of version don't time out when searching for
+ pipelines
+merge_request:
+author:
+type: performance