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