summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-11-10 15:49:36 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2017-11-10 15:49:36 +0000
commit0517b9e341a2960c54faa69717628225ed50c418 (patch)
tree0a12dd9b35789f514cc5d713434773cde5d7e3f4
parent820c646cbba85b6a8696ad51c886f791f7ab4a3e (diff)
parentec73ecb0a88401932efc7b2b382db6905027b126 (diff)
downloadgitlab-ce-0517b9e341a2960c54faa69717628225ed50c418.tar.gz
Merge branch 'fix-502-mrs-with-lots-of-versions' into 'master'
Fix another timeout when searching for pipelines Closes #39054 See merge request gitlab-org/gitlab-ce!15322
-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