Commit 167c8141 authored by Marc Shaw's avatar Marc Shaw

Memoize force_push when updating a merge request

Merge Request: gitlab.com/gitlab-org/gitlab/-/merge_requests/53536
Issue: gitlab.com/gitlab-org/gitlab/-/issues/218410
parent 3fd4e9d9
---
title: Speed up update merge request worker by memoizing whether a push is a force or not
merge_request: 53536
author:
type: performance
...@@ -33,7 +33,9 @@ module Gitlab ...@@ -33,7 +33,9 @@ module Gitlab
end end
def force_push? def force_push?
Gitlab::Checks::ForcePush.force_push?(@project, @oldrev, @newrev) strong_memoize(:force_push) do
Gitlab::Checks::ForcePush.force_push?(@project, @oldrev, @newrev)
end
end end
def branch_push? def branch_push?
......
...@@ -86,6 +86,16 @@ RSpec.describe Gitlab::Git::Push do ...@@ -86,6 +86,16 @@ RSpec.describe Gitlab::Git::Push do
it { is_expected.to be_force_push } it { is_expected.to be_force_push }
end end
context 'when called muiltiple times' do
it 'does not make make multiple calls to the force push check' do
expect(Gitlab::Checks::ForcePush).to receive(:force_push?).once
2.times do
subject.force_push?
end
end
end
end end
describe '#branch_added?' do describe '#branch_added?' 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