Commit c264427e authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Removes unneeded preloading in Markdown rendering

Improves rendering and redaction performance of issue and merge
request references by not preloading associations that we do not
need

Changelog: performance
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62273
parent 3a95b615
......@@ -66,14 +66,7 @@ module Banzai
# These associations are primarily used for checking permissions.
# Eager loading these ensures we don't end up running dozens of
# queries in this process.
project: [
{ namespace: :owner },
{ group: [:owners, :group_members] },
:invited_groups,
:project_members,
:project_feature,
:route
]
project: [:namespace, :project_feature, :route]
}
),
self.class.data_attribute
......
......@@ -17,14 +17,7 @@ module Banzai
# These associations are primarily used for checking permissions.
# Eager loading these ensures we don't end up running dozens of
# queries in this process.
target_project: [
{ namespace: [:owner, :route] },
{ group: [:owners, :group_members] },
:invited_groups,
:project_members,
:project_feature,
:route
]
target_project: [{ namespace: :route }, :project_feature, :route]
}),
self.class.data_attribute
)
......
......@@ -5,9 +5,11 @@ require 'spec_helper'
RSpec.describe Banzai::ReferenceParser::IssueParser do
include ReferenceParserHelpers
let(:project) { create(:project, :public) }
let(:user) { create(:user) }
let(:issue) { create(:issue, project: project) }
let_it_be(:group) { create(:group, :public) }
let_it_be(:project) { create(:project, :public, group: group) }
let_it_be(:user) { create(:user) }
let_it_be(:issue) { create(:issue, project: project) }
let(:link) { empty_html_link }
subject { described_class.new(Banzai::RenderContext.new(project, user)) }
......@@ -121,7 +123,7 @@ RSpec.describe Banzai::ReferenceParser::IssueParser do
end
end
context 'when checking multiple merge requests on another project' do
context 'when checking multiple issues on another project' do
let(:other_project) { create(:project, :public) }
let(:other_issue) { create(:issue, project: other_project) }
......
......@@ -5,9 +5,11 @@ require 'spec_helper'
RSpec.describe Banzai::ReferenceParser::MergeRequestParser do
include ReferenceParserHelpers
let(:group) { create(:group, :public) }
let(:project) { create(:project, :public, group: group) }
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let(:merge_request) { create(:merge_request, source_project: project) }
subject(:parser) { described_class.new(Banzai::RenderContext.new(merge_request.target_project, user)) }
let(:link) { empty_html_link }
......
......@@ -21,6 +21,11 @@ module ReferenceParserHelpers
end
control = record_queries.call(control_links)
create(:group_member, group: project.group) if project.group
create(:project_member, project: project)
create(:project_group_link, project: project)
actual = record_queries.call(actual_links)
expect(actual.count).to be <= control.count
......
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