Commit ee1e606f authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'move-recursive-ns-query-to-inner-join' into 'master'

Move recursive namespace query to INNER JOIN [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!56078
parents 6f95667d 2651bbe8
...@@ -260,8 +260,13 @@ class Namespace < ApplicationRecord ...@@ -260,8 +260,13 @@ class Namespace < ApplicationRecord
# Includes projects from this namespace and projects from all subgroups # Includes projects from this namespace and projects from all subgroups
# that belongs to this namespace # that belongs to this namespace
def all_projects def all_projects
namespace = user? ? self : self_and_descendants return Project.where(namespace: self) if user?
Project.where(namespace: namespace)
if Feature.enabled?(:recursive_namespace_lookup_as_inner_join, self)
Project.joins("INNER JOIN (#{self_and_descendants.select(:id).to_sql}) namespaces ON namespaces.id=projects.namespace_id")
else
Project.where(namespace: self_and_descendants)
end
end end
# Includes pipelines from this namespace and pipelines from all subgroups # Includes pipelines from this namespace and pipelines from all subgroups
......
---
name: recursive_namespace_lookup_as_inner_join
introduced_by_url:
rollout_issue_url:
milestone: '13.10'
type: development
group: group::optimize
default_enabled: false
...@@ -897,10 +897,24 @@ RSpec.describe Namespace do ...@@ -897,10 +897,24 @@ RSpec.describe Namespace do
it { expect(namespace.all_projects.to_a).to match_array([project2, project1]) } it { expect(namespace.all_projects.to_a).to match_array([project2, project1]) }
it { expect(child.all_projects.to_a).to match_array([project2]) } it { expect(child.all_projects.to_a).to match_array([project2]) }
it 'queries for the namespace and its descendants' do context 'when recursive_namespace_lookup_as_inner_join feature flag is on' do
expect(Project).to receive(:where).with(namespace: [namespace, child]) before do
stub_feature_flags(recursive_namespace_lookup_as_inner_join: true)
end
it 'queries for the namespace and its descendants' do
expect(namespace.all_projects).to match_array([project1, project2])
end
end
namespace.all_projects context 'when recursive_namespace_lookup_as_inner_join feature flag is off' do
before do
stub_feature_flags(recursive_namespace_lookup_as_inner_join: false)
end
it 'queries for the namespace and its descendants' do
expect(namespace.all_projects).to match_array([project1, project2])
end
end 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