Commit a15f05cf authored by Igor's avatar Igor Committed by Kamil Trzciński

Run check_mergeability only if merge status requires it

If merge_status is not unchecked there's no need to
run whole MergeabilityCheckService because the
merge_status column won't be updated in this case
parent 45b407a3
...@@ -796,6 +796,8 @@ class MergeRequest < ApplicationRecord ...@@ -796,6 +796,8 @@ class MergeRequest < ApplicationRecord
end end
def check_mergeability def check_mergeability
return if Feature.enabled?(:merge_requests_conditional_mergeability_check, default_enabled: true) && !recheck_merge_status?
MergeRequests::MergeabilityCheckService.new(self).execute(retry_lease: false) MergeRequests::MergeabilityCheckService.new(self).execute(retry_lease: false)
end end
# rubocop: enable CodeReuse/ServiceClass # rubocop: enable CodeReuse/ServiceClass
......
---
title: Run check_mergeability only if merge status requires it
merge_request: 19364
author:
type: performance
...@@ -2177,6 +2177,50 @@ describe MergeRequest do ...@@ -2177,6 +2177,50 @@ describe MergeRequest do
end end
end end
describe '#check_mergeability' do
let(:mergeability_service) { double }
before do
allow(MergeRequests::MergeabilityCheckService).to receive(:new) do
mergeability_service
end
end
context 'if the merge status is unchecked' do
before do
subject.mark_as_unchecked!
end
it 'executes MergeabilityCheckService' do
expect(mergeability_service).to receive(:execute)
subject.check_mergeability
end
end
context 'if the merge status is checked' do
context 'and feature flag is enabled' do
it 'executes MergeabilityCheckService' do
expect(mergeability_service).not_to receive(:execute)
subject.check_mergeability
end
end
context 'and feature flag is disabled' do
before do
stub_feature_flags(merge_requests_conditional_mergeability_check: false)
end
it 'does not execute MergeabilityCheckService' do
expect(mergeability_service).to receive(:execute)
subject.check_mergeability
end
end
end
end
describe '#mergeable_state?' do describe '#mergeable_state?' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
......
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