summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-01-11 16:20:13 +0000
committerSean McGivern <sean@gitlab.com>2018-01-12 13:19:05 +0000
commitf3cf8cc8d1625ae1cd532474191739cd36419425 (patch)
treeeb837a49f9d8d9546a505f62b62e2b59307bb2b4 /app
parent678a00d60a21fcd39fa5c8043fadc4a94e618f4d (diff)
downloadgitlab-ce-f3cf8cc8d1625ae1cd532474191739cd36419425.tar.gz
Only search for MR revert commits on notes after MR was merged41807-15665-consistently-502s-because-it-fetches-every-commit
If we search for notes before the MR was merged, we have to load every commit that was ever part of the MR, or mentioned in a push. In extreme cases, this can be tens of thousands of commits to load, but we know they can't revert the merge commit, because they are from before the MR was merged. In the (rare) case that we don't have a `merged_at` value for the MR, we can still search all notes.
Diffstat (limited to 'app')
-rw-r--r--app/models/commit.rb5
-rw-r--r--app/models/merge_request.rb11
2 files changed, 13 insertions, 3 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 39d7f5b159d..ede8ad301e4 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -342,10 +342,11 @@ class Commit
@merged_merge_request_hash[current_user]
end
- def has_been_reverted?(current_user, noteable = self)
+ def has_been_reverted?(current_user, notes_association = nil)
ext = all_references(current_user)
+ notes_association ||= notes_with_associations
- noteable.notes_with_associations.system.each do |note|
+ notes_association.system.each do |note|
note.all_references(current_user, extractor: ext)
end
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index ef58816937c..8efe7d41f37 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -982,7 +982,16 @@ class MergeRequest < ActiveRecord::Base
end
def can_be_reverted?(current_user)
- merge_commit && !merge_commit.has_been_reverted?(current_user, self)
+ return false unless merge_commit
+
+ merged_at = metrics&.merged_at
+ notes_association = notes_with_associations
+
+ if merged_at
+ notes_association = notes_association.where('created_at > ?', merged_at)
+ end
+
+ !merge_commit.has_been_reverted?(current_user, notes_association)
end
def can_be_cherry_picked?