Commit c37238d9 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Apply optimizations to merge request reference rendering

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/271242

* Short-circuit cross_namespace check
* Use memoized result of the full_path

Changelog: performance
parent 9efb5c2f
......@@ -2663,7 +2663,7 @@ class Project < ApplicationRecord
def cross_namespace_reference?(from)
case from
when Project
namespace != from.namespace
namespace_id != from.namespace_id
when Namespace
namespace != from
when User
......
---
title: Apply optimizations to merge request reference rendering
merge_request: 60500
author:
type: performance
......@@ -616,7 +616,7 @@ RSpec.describe Vulnerability do
end
context 'when cross-project in different namespace' do
let(:another_namespace) { build(:namespace, path: 'another-namespace') }
let(:another_namespace) { build(:namespace, id: non_existing_record_id, path: 'another-namespace') }
let(:another_namespace_project) { build(:project, path: 'another-project', namespace: another_namespace) }
it 'returns complete path to the vulnerability' do
......
......@@ -58,7 +58,7 @@ module Banzai
end
def data_attributes_for(text, parent, object, **data)
super.merge(project_path: parent.full_path, iid: object.iid, mr_title: object.title)
super.merge(project_path: current_parent_path, iid: object.iid, mr_title: object.title)
end
private
......
......@@ -512,7 +512,7 @@ RSpec.describe DesignManagement::Design do
end
describe '#to_reference' do
let(:namespace) { build(:namespace, path: 'sample-namespace') }
let(:namespace) { build(:namespace, id: non_existing_record_id, path: 'sample-namespace') }
let(:project) { build(:project, name: 'sample-project', namespace: namespace) }
let(:group) { create(:group, name: 'Group', path: 'sample-group') }
let(:issue) { build(:issue, iid: 1, project: project) }
......
......@@ -297,7 +297,7 @@ RSpec.describe Issue do
end
context 'when cross-project in different namespace' do
let(:another_namespace) { build(:namespace, path: 'another-namespace') }
let(:another_namespace) { build(:namespace, id: non_existing_record_id, path: 'another-namespace') }
let(:another_namespace_project) { build(:project, path: 'another-project', namespace: another_namespace) }
it 'returns complete path to the issue' 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