Commit 94c17251 authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Nick Thomas

Only schedule push-mirror updates once per push

Before we were scheduling the update once for each pushed ref through
the Git::(Branch|Tag)PushService. But all the refs will be pushed
every time, meaning that most of these updates would be no-ops.

This moves the updated out into the PostReceive worker, so this is
only scheduled once per push.
parent 66d2e01e
...@@ -15,8 +15,6 @@ module Git ...@@ -15,8 +15,6 @@ module Git
# Not a hook, but it needs access to the list of changed commits # Not a hook, but it needs access to the list of changed commits
enqueue_invalidate_cache enqueue_invalidate_cache
update_remote_mirrors
success success
end end
...@@ -121,13 +119,6 @@ module Git ...@@ -121,13 +119,6 @@ module Git
{} {}
end end
def update_remote_mirrors
return unless project.has_remote_mirror?
project.mark_stuck_remote_mirrors_as_failed!
project.update_remote_mirrors
end
def log_pipeline_errors(exception) def log_pipeline_errors(exception)
data = { data = {
class: self.class.name, class: self.class.name,
......
...@@ -57,13 +57,6 @@ module Git ...@@ -57,13 +57,6 @@ module Git
Ci::StopEnvironmentsService.new(project, current_user).execute(branch_name) Ci::StopEnvironmentsService.new(project, current_user).execute(branch_name)
end end
def update_remote_mirrors
return unless project.has_remote_mirror?
project.mark_stuck_remote_mirrors_as_failed!
project.update_remote_mirrors
end
def execute_related_hooks def execute_related_hooks
BranchHooksService.new(project, current_user, params).execute BranchHooksService.new(project, current_user, params).execute
end end
......
...@@ -70,6 +70,7 @@ class PostReceive ...@@ -70,6 +70,7 @@ class PostReceive
refs << ref refs << ref
end end
update_remote_mirrors(post_received)
after_project_changes_hooks(post_received, user, refs.to_a, changes) after_project_changes_hooks(post_received, user, refs.to_a, changes)
end end
...@@ -93,6 +94,16 @@ class PostReceive ...@@ -93,6 +94,16 @@ class PostReceive
) )
end end
def update_remote_mirrors(post_received)
return unless post_received.includes_branches? || post_received.includes_tags?
project = post_received.project
return unless project.has_remote_mirror?
project.mark_stuck_remote_mirrors_as_failed!
project.update_remote_mirrors
end
def after_project_changes_hooks(post_received, user, refs, changes) def after_project_changes_hooks(post_received, user, refs, changes)
hook_data = Gitlab::DataBuilder::Repository.update(post_received.project, user, changes, refs) hook_data = Gitlab::DataBuilder::Repository.update(post_received.project, user, changes, refs)
SystemHooksService.new.execute_hooks(hook_data, :repository_update_hooks) SystemHooksService.new.execute_hooks(hook_data, :repository_update_hooks)
......
---
title: Only schedule updating push-mirrors once per push
merge_request: 17902
author:
type: performance
...@@ -85,78 +85,4 @@ describe Git::BaseHooksService do ...@@ -85,78 +85,4 @@ describe Git::BaseHooksService do
end end
end end
end end
describe 'with remote mirrors' do
class TestService < described_class
def commits
[]
end
end
let(:project) { create(:project, :repository, :remote_mirror) }
subject { TestService.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) }
before do
expect(subject).to receive(:execute_project_hooks)
end
context 'when remote mirror feature is enabled' do
it 'fails stuck remote mirrors' do
allow(project).to receive(:update_remote_mirrors).and_return(project.remote_mirrors)
expect(project).to receive(:mark_stuck_remote_mirrors_as_failed!)
subject.execute
end
it 'updates remote mirrors' do
expect(project).to receive(:update_remote_mirrors)
subject.execute
end
end
context 'when remote mirror feature is disabled' do
before do
stub_application_setting(mirror_available: false)
end
context 'with remote mirrors global setting overridden' do
before do
project.remote_mirror_available_overridden = true
end
it 'fails stuck remote mirrors' do
allow(project).to receive(:update_remote_mirrors).and_return(project.remote_mirrors)
expect(project).to receive(:mark_stuck_remote_mirrors_as_failed!)
subject.execute
end
it 'updates remote mirrors' do
expect(project).to receive(:update_remote_mirrors)
subject.execute
end
end
context 'without remote mirrors global setting overridden' do
before do
project.remote_mirror_available_overridden = false
end
it 'does not fails stuck remote mirrors' do
expect(project).not_to receive(:mark_stuck_remote_mirrors_as_failed!)
subject.execute
end
it 'does not updates remote mirrors' do
expect(project).not_to receive(:update_remote_mirrors)
subject.execute
end
end
end
end
end end
...@@ -19,12 +19,6 @@ describe Git::BranchHooksService do ...@@ -19,12 +19,6 @@ describe Git::BranchHooksService do
described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end end
it 'update remote mirrors' do
expect(service).to receive(:update_remote_mirrors).and_call_original
service.execute
end
describe "Git Push Data" do describe "Git Push Data" do
subject(:push_data) { service.send(:push_data) } subject(:push_data) { service.send(:push_data) }
......
...@@ -18,12 +18,6 @@ describe Git::TagHooksService, :service do ...@@ -18,12 +18,6 @@ describe Git::TagHooksService, :service do
described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end end
it 'update remote mirrors' do
expect(service).to receive(:update_remote_mirrors).and_call_original
service.execute
end
describe 'System hooks' do describe 'System hooks' do
it 'Executes system hooks' do it 'Executes system hooks' do
push_data = service.send(:push_data) push_data = service.send(:push_data)
......
...@@ -61,6 +61,16 @@ describe PostReceive do ...@@ -61,6 +61,16 @@ describe PostReceive do
end end
end end
shared_examples 'not updating remote mirrors' do
it 'does not schedule an update' do
expect(project).not_to receive(:has_remote_mirror?)
expect(project).not_to receive(:mark_stuck_remote_mirrors_as_failed!)
expect(project).not_to receive(:update_remote_mirrors)
perform
end
end
context 'empty changes' do context 'empty changes' do
it "does not call any PushService but runs after project hooks" do it "does not call any PushService but runs after project hooks" do
expect(Git::BranchPushService).not_to receive(:new) expect(Git::BranchPushService).not_to receive(:new)
...@@ -69,6 +79,8 @@ describe PostReceive do ...@@ -69,6 +79,8 @@ describe PostReceive do
perform(changes: "") perform(changes: "")
end end
it_behaves_like 'not updating remote mirrors'
end end
context 'unidentified user' do context 'unidentified user' do
...@@ -88,6 +100,16 @@ describe PostReceive do ...@@ -88,6 +100,16 @@ describe PostReceive do
allow(Gitlab::GlRepository).to receive(:parse).and_return([project, Gitlab::GlRepository::PROJECT]) allow(Gitlab::GlRepository).to receive(:parse).and_return([project, Gitlab::GlRepository::PROJECT])
end end
shared_examples 'updating remote mirrors' do
it 'schedules an update if the project had mirrors' do
expect(project).to receive(:has_remote_mirror?).and_return(true)
expect(project).to receive(:mark_stuck_remote_mirrors_as_failed!)
expect(project).to receive(:update_remote_mirrors)
perform
end
end
context "branches" do context "branches" do
let(:changes) do let(:changes) do
<<~EOF <<~EOF
...@@ -126,6 +148,8 @@ describe PostReceive do ...@@ -126,6 +148,8 @@ describe PostReceive do
perform perform
end end
it_behaves_like 'updating remote mirrors'
context 'with a default branch' do context 'with a default branch' do
let(:changes) do let(:changes) do
<<~EOF <<~EOF
...@@ -191,6 +215,8 @@ describe PostReceive do ...@@ -191,6 +215,8 @@ describe PostReceive do
perform perform
end end
it_behaves_like 'updating remote mirrors'
end end
context "merge-requests" do context "merge-requests" do
...@@ -202,6 +228,8 @@ describe PostReceive do ...@@ -202,6 +228,8 @@ describe PostReceive do
perform perform
end end
it_behaves_like 'not updating remote mirrors'
end end
context "gitlab-ci.yml" do context "gitlab-ci.yml" do
......
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