Commit 17a3ad8b authored by James Fargher's avatar James Fargher

Merge branch '199197-make-has-been-reverted-check-cheaper' into 'master'

Make Commit#has_been_reverted? cheaper

Closes #21049 and #199197

See merge request gitlab-org/gitlab!26784
parents b67486fe 8ba07f7d
......@@ -415,7 +415,7 @@ class Commit
end
def has_been_reverted?(current_user, notes_association = nil)
ext = all_references(current_user)
ext = Gitlab::ReferenceExtractor.new(project, current_user)
notes_association ||= notes_with_associations
notes_association.system.each do |note|
......
---
title: Improve performance of the "has this commit been reverted?" check
merge_request: 26784
author:
type: performance
......@@ -137,29 +137,4 @@ describe CommitRange do
end
end
end
describe '#has_been_reverted?' do
let(:user) { create(:user) }
let(:issue) { create(:issue, author: user, project: project) }
it 'returns true if the commit has been reverted' do
create(:note_on_issue,
noteable: issue,
system: true,
note: commit1.revert_description(user),
project: issue.project)
expect_next_instance_of(Commit) do |commit|
expect(commit).to receive(:reverts_commit?)
.with(commit1, user)
.and_return(true)
end
expect(commit1.has_been_reverted?(user, issue.notes_with_associations)).to eq(true)
end
it 'returns false if the commit has not been reverted' do
expect(commit1.has_been_reverted?(user, issue.notes_with_associations)).to eq(false)
end
end
end
......@@ -821,4 +821,29 @@ eos
expect(commit.has_signature?).to be_falsey
end
end
describe '#has_been_reverted?' do
let(:user) { create(:user) }
let(:issue) { create(:issue, author: user, project: project) }
it 'returns true if the commit has been reverted' do
create(:note_on_issue,
noteable: issue,
system: true,
note: commit.revert_description(user),
project: issue.project)
expect_next_instance_of(Commit) do |revert_commit|
expect(revert_commit).to receive(:reverts_commit?)
.with(commit, user)
.and_return(true)
end
expect(commit.has_been_reverted?(user, issue.notes_with_associations)).to eq(true)
end
it 'returns false if the commit has not been reverted' do
expect(commit.has_been_reverted?(user, issue.notes_with_associations)).to eq(false)
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