diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 1ede7749791d687db63c9c5ceae26ca142bbbc97..805a7f906dbdb60dae96bbf32c244e3a5690d173 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -1117,23 +1117,7 @@ def ensure_merge_request_diff merge_request_diff.persisted? || create_merge_request_diff end - def eager_fetch_ref! - return unless valid? - - # has_internal_id normally attempts to allocate the iid in the - # before_create hook, but we need the iid to be available before - # that to fetch the ref into the target project. - track_target_project_iid! - ensure_target_project_iid! - - fetch_ref! - # Prevent the after_create hook from fetching the source branch again. - @skip_fetch_ref = true - end - def create_merge_request_diff - # Callers such as MergeRequests::BuildService may not call eager_fetch_ref!. Just - # in case they haven't, we fetch the ref. fetch_ref! unless skip_fetch_ref # n+1: https://gitlab.com/gitlab-org/gitlab/-/issues/19377 diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index e6dc113936323f16e470f34052858f09cd11ea35..f7a2daa6da15ab1ebf0ce60088efa0d5b8aef4db 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -4752,30 +4752,6 @@ def create_build(pipeline, coverage, name) end end - describe '#eager_fetch_ref!' do - let(:project) { create(:project, :repository) } - - # We use build instead of create to test that an IID is allocated - subject { build(:merge_request, source_project: project) } - - it 'fetches the ref and expires the ancestor cache' do - expect(subject).to receive(:expire_ancestor_cache).and_call_original - expect(subject.iid).to be_nil - - expect { subject.eager_fetch_ref! }.to change { subject.iid.to_i }.by(1) - - expect(subject.target_project.repository.ref_exists?(subject.ref_path)).to be_truthy - end - - it 'only fetches the ref once after saved' do - expect(subject.target_project.repository).to receive(:fetch_source_branch!).once.and_call_original - - subject.save! - - expect(subject.target_project.repository.ref_exists?(subject.ref_path)).to be_truthy - end - end - describe 'removing a merge request' do it 'refreshes the number of open merge requests of the target project' do project = subject.target_project