Commit b4f34e14 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'load_project_features' into 'master'

Preload project features in reference parser

Closes #43094

See merge request gitlab-org/gitlab-ce!22008
parents 88fa9a3c 7f4452d4
---
title: Mitigate N+1 queries when parsing commit references in comments.
merge_request:
author:
type: performance
...@@ -215,7 +215,7 @@ module Banzai ...@@ -215,7 +215,7 @@ module Banzai
# #
def projects_for_nodes(nodes) def projects_for_nodes(nodes)
@projects_for_nodes ||= @projects_for_nodes ||=
grouped_objects_for_nodes(nodes, Project, 'data-project') grouped_objects_for_nodes(nodes, Project.includes(:project_feature), 'data-project')
end end
def can?(user, permission, subject = :global) def can?(user, permission, subject = :global)
......
...@@ -120,4 +120,22 @@ describe Banzai::ReferenceParser::CommitParser do ...@@ -120,4 +120,22 @@ describe Banzai::ReferenceParser::CommitParser do
expect(subject.find_commits(project, %w{123})).to eq([]) expect(subject.find_commits(project, %w{123})).to eq([])
end end
end end
context 'when checking commits on another projects' do
let(:control_links) do
[commit_link]
end
let(:actual_links) do
control_links + [commit_link, commit_link]
end
def commit_link
project = create(:project, :repository, :public)
Nokogiri::HTML.fragment(%Q{<a data-commit="#{project.commit.id}" data-project="#{project.id}"></a>}).children[0]
end
it_behaves_like 'no project N+1 queries'
end
end end
...@@ -3,7 +3,7 @@ module ReferenceParserHelpers ...@@ -3,7 +3,7 @@ module ReferenceParserHelpers
Nokogiri::HTML.fragment('<a></a>').children[0] Nokogiri::HTML.fragment('<a></a>').children[0]
end end
shared_examples 'no N+1 queries' do shared_examples 'no project N+1 queries' do
it 'avoids N+1 queries in #nodes_visible_to_user', :request_store do it 'avoids N+1 queries in #nodes_visible_to_user', :request_store do
context = Banzai::RenderContext.new(project, user) context = Banzai::RenderContext.new(project, user)
...@@ -19,6 +19,10 @@ module ReferenceParserHelpers ...@@ -19,6 +19,10 @@ module ReferenceParserHelpers
expect(actual.count).to be <= control.count expect(actual.count).to be <= control.count
expect(actual.cached_count).to be <= control.cached_count expect(actual.cached_count).to be <= control.cached_count
end end
end
shared_examples 'no N+1 queries' do
it_behaves_like 'no project N+1 queries'
it 'avoids N+1 queries in #records_for_nodes', :request_store do it 'avoids N+1 queries in #records_for_nodes', :request_store do
context = Banzai::RenderContext.new(project, user) context = Banzai::RenderContext.new(project, user)
......
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