Commit da480ca2 authored by Igor Drozdov's avatar Igor Drozdov

Remove memoization on processing ref changes

parent a7e0fc7f
...@@ -42,7 +42,7 @@ module Git ...@@ -42,7 +42,7 @@ module Git
push_service_class = push_service_class_for(ref_type) push_service_class = push_service_class_for(ref_type)
create_bulk_push_event = changes.size > Gitlab::CurrentSettings.push_event_activities_limit create_bulk_push_event = changes.size > Gitlab::CurrentSettings.push_event_activities_limit
merge_request_branches = merge_request_branches_for(changes) merge_request_branches = merge_request_branches_for(ref_type, changes)
changes.each do |change| changes.each do |change|
push_service_class.new( push_service_class.new(
...@@ -74,8 +74,10 @@ module Git ...@@ -74,8 +74,10 @@ module Git
Git::BranchPushService Git::BranchPushService
end end
def merge_request_branches_for(changes) def merge_request_branches_for(ref_type, changes)
@merge_requests_branches ||= MergeRequests::PushedBranchesService.new(project, current_user, changes: changes).execute return [] if ref_type == :tag
MergeRequests::PushedBranchesService.new(project, current_user, changes: changes).execute
end end
end end
end end
---
title: Fix wrong caching logic in ProcessRefChangesService
merge_request: 40821
author:
type: fixed
...@@ -172,23 +172,31 @@ RSpec.describe Git::ProcessRefChangesService do ...@@ -172,23 +172,31 @@ RSpec.describe Git::ProcessRefChangesService do
[ [
{ index: 0, oldrev: Gitlab::Git::BLANK_SHA, newrev: '789012', ref: "#{ref_prefix}/create1" }, { index: 0, oldrev: Gitlab::Git::BLANK_SHA, newrev: '789012', ref: "#{ref_prefix}/create1" },
{ index: 1, oldrev: Gitlab::Git::BLANK_SHA, newrev: '789013', ref: "#{ref_prefix}/create2" }, { index: 1, oldrev: Gitlab::Git::BLANK_SHA, newrev: '789013', ref: "#{ref_prefix}/create2" },
{ index: 2, oldrev: Gitlab::Git::BLANK_SHA, newrev: '789014', ref: "#{ref_prefix}/create3" } { index: 2, oldrev: Gitlab::Git::BLANK_SHA, newrev: '789014', ref: "#{ref_prefix}/create3" },
{ index: 3, oldrev: '789015', newrev: '789016', ref: "#{ref_prefix}/changed1" },
{ index: 4, oldrev: '789017', newrev: '789018', ref: "#{ref_prefix}/changed2" },
{ index: 5, oldrev: '789019', newrev: Gitlab::Git::BLANK_SHA, ref: "#{ref_prefix}/removed1" },
{ index: 6, oldrev: '789020', newrev: Gitlab::Git::BLANK_SHA, ref: "#{ref_prefix}/removed2" }
] ]
end end
let(:git_changes) { double(branch_changes: branch_changes, tag_changes: tag_changes) } let(:git_changes) { double(branch_changes: branch_changes, tag_changes: tag_changes) }
it 'schedules job for existing merge requests' do before do
expect_next_instance_of(MergeRequests::PushedBranchesService) do |service| allow(MergeRequests::PushedBranchesService).to receive(:new).and_return(
expect(service).to receive(:execute).and_return(%w(create1 create2)) double(execute: %w(create1 create2)), double(execute: %w(changed1)), double(execute: %w(removed2))
end )
end
it 'schedules job for existing merge requests' do
expect(UpdateMergeRequestsWorker).to receive(:perform_async) expect(UpdateMergeRequestsWorker).to receive(:perform_async)
.with(project.id, user.id, Gitlab::Git::BLANK_SHA, '789012', "#{ref_prefix}/create1").ordered .with(project.id, user.id, Gitlab::Git::BLANK_SHA, '789012', "#{ref_prefix}/create1").ordered
expect(UpdateMergeRequestsWorker).to receive(:perform_async) expect(UpdateMergeRequestsWorker).to receive(:perform_async)
.with(project.id, user.id, Gitlab::Git::BLANK_SHA, '789013', "#{ref_prefix}/create2").ordered .with(project.id, user.id, Gitlab::Git::BLANK_SHA, '789013', "#{ref_prefix}/create2").ordered
expect(UpdateMergeRequestsWorker).not_to receive(:perform_async) expect(UpdateMergeRequestsWorker).to receive(:perform_async)
.with(project.id, user.id, Gitlab::Git::BLANK_SHA, '789014', "#{ref_prefix}/create3").ordered .with(project.id, user.id, '789015', '789016', "#{ref_prefix}/changed1").ordered
expect(UpdateMergeRequestsWorker).to receive(:perform_async)
.with(project.id, user.id, '789020', Gitlab::Git::BLANK_SHA, "#{ref_prefix}/removed2").ordered
subject.execute subject.execute
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