Commit c1063084 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'preload-project-features-for-namespace-virtual-domain' into 'master'

Preload associations needed by Namespace#pages_virtual_domain

See merge request gitlab-org/gitlab!25499
parents 13967e02 6af35b45
......@@ -327,7 +327,10 @@ class Namespace < ApplicationRecord
end
def pages_virtual_domain
Pages::VirtualDomain.new(all_projects_with_pages, trim_prefix: full_path)
Pages::VirtualDomain.new(
all_projects_with_pages.includes(:route, :project_feature),
trim_prefix: full_path
)
end
def closest_setting(name)
......
......@@ -983,6 +983,24 @@ describe Namespace do
expect(virtual_domain.lookup_paths).not_to be_empty
end
end
it 'preloads project_feature and route' do
project2 = create(:project, namespace: namespace)
project3 = create(:project, namespace: namespace)
project.mark_pages_as_deployed
project2.mark_pages_as_deployed
project3.mark_pages_as_deployed
virtual_domain = namespace.pages_virtual_domain
queries = ActiveRecord::QueryRecorder.new { virtual_domain.lookup_paths }
# 1 to load projects
# 1 to preload project features
# 1 to load routes
expect(queries.count).to eq(3)
end
end
end
......
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