Commit ac439902 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'remove-source-branch-exists-memoization' into 'master'

Remove the memoization of source_branch_exists on merge request

See merge request gitlab-org/gitlab!39944
parents 2048ebf1 244860a1
...@@ -105,7 +105,6 @@ class MergeRequest < ApplicationRecord ...@@ -105,7 +105,6 @@ class MergeRequest < ApplicationRecord
after_create :ensure_merge_request_diff after_create :ensure_merge_request_diff
after_update :clear_memoized_shas after_update :clear_memoized_shas
after_update :clear_memoized_source_branch_exists
after_update :reload_diff_if_branch_changed after_update :reload_diff_if_branch_changed
after_commit :ensure_metrics, on: [:create, :update], unless: :importing? after_commit :ensure_metrics, on: [:create, :update], unless: :importing?
after_commit :expire_etag_cache, unless: :importing? after_commit :expire_etag_cache, unless: :importing?
...@@ -871,10 +870,6 @@ class MergeRequest < ApplicationRecord ...@@ -871,10 +870,6 @@ class MergeRequest < ApplicationRecord
clear_memoization(:target_branch_head) clear_memoization(:target_branch_head)
end end
def clear_memoized_source_branch_exists
clear_memoization(:source_branch_exists)
end
def reload_diff_if_branch_changed def reload_diff_if_branch_changed
if (saved_change_to_source_branch? || saved_change_to_target_branch?) && if (saved_change_to_source_branch? || saved_change_to_target_branch?) &&
(source_branch_head && target_branch_head) (source_branch_head && target_branch_head)
...@@ -1126,11 +1121,9 @@ class MergeRequest < ApplicationRecord ...@@ -1126,11 +1121,9 @@ class MergeRequest < ApplicationRecord
end end
def source_branch_exists? def source_branch_exists?
strong_memoize(:source_branch_exists) do return false unless self.source_project
next false unless self.source_project
self.source_project.repository.branch_exists?(self.source_branch) self.source_project.repository.branch_exists?(self.source_branch)
end
end end
def target_branch_exists? def target_branch_exists?
......
...@@ -1257,10 +1257,8 @@ RSpec.describe MergeRequest do ...@@ -1257,10 +1257,8 @@ RSpec.describe MergeRequest do
let(:repository) { merge_request.source_project.repository } let(:repository) { merge_request.source_project.repository }
context 'when the source project is set' do context 'when the source project is set' do
it 'memoizes the value and returns the result' do it 'returns true when the branch exists' do
expect(repository).to receive(:branch_exists?).once.with(merge_request.source_branch).and_return(true) expect(merge_request.source_branch_exists?).to eq(true)
2.times { expect(merge_request.source_branch_exists?).to eq(true) }
end end
end end
......
...@@ -30,7 +30,6 @@ RSpec.describe MergeRequests::Conflicts::ListService do ...@@ -30,7 +30,6 @@ RSpec.describe MergeRequests::Conflicts::ListService do
it 'returns a falsey value when one of the MR branches is missing' do it 'returns a falsey value when one of the MR branches is missing' do
merge_request = create_merge_request('conflict-resolvable') merge_request = create_merge_request('conflict-resolvable')
merge_request.project.repository.rm_branch(merge_request.author, 'conflict-resolvable') merge_request.project.repository.rm_branch(merge_request.author, 'conflict-resolvable')
merge_request.clear_memoized_source_branch_exists
expect(conflicts_service(merge_request).can_be_resolved_in_ui?).to be_falsey expect(conflicts_service(merge_request).can_be_resolved_in_ui?).to be_falsey
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