Commit 5b8dcbe6 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'revert-inner-join-cte-fix' into 'master'

Revert move-recursive-ns-query-to-inner-join [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!57131
parents 85c64952 afdb0044
......@@ -261,13 +261,8 @@ class Namespace < ApplicationRecord
# Includes projects from this namespace and projects from all subgroups
# that belongs to this namespace
def all_projects
return Project.where(namespace: self) if user?
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
namespace = user? ? self : self_and_descendants
Project.where(namespace: namespace)
end
# Includes pipelines from this namespace and pipelines from all subgroups
......
---
title: Remove the recursive_namespace_lookup_as_inner_join feature flag
merge_request: 57131
author:
type: other
---
name: recursive_namespace_lookup_as_inner_join
introduced_by_url:
rollout_issue_url:
milestone: '13.10'
type: development
group: group::optimize
default_enabled: false
......@@ -13,12 +13,5 @@ class Analytics::DevopsAdoption::Segment < ApplicationRecord
scope :ordered_by_name, -> { includes(:namespace).order('"namespaces"."name" ASC') }
scope :for_namespaces, -> (namespaces) { where(namespace_id: namespaces) }
scope :for_parent, -> (namespace) {
if Feature.enabled?(:recursive_namespace_lookup_as_inner_join, namespace)
join_sql = namespace.self_and_descendants.to_sql
joins("INNER JOIN (#{join_sql}) namespaces ON namespaces.id=#{self.arel_table.name}.namespace_id")
else
for_namespaces(namespace.self_and_descendants)
end
}
scope :for_parent, -> (namespace) { for_namespaces(namespace.self_and_descendants) }
end
......@@ -52,10 +52,6 @@ RSpec.describe Analytics::DevopsAdoption::Segment, type: :model do
subject(:segments) { described_class.for_parent(group) }
before do
stub_feature_flags(recursive_namespace_lookup_as_inner_join: true)
end
it 'selects segments for given namespace only' do
expect(segments).to match_array([segment1, segment2])
end
......
......@@ -911,24 +911,10 @@ RSpec.describe Namespace do
it { expect(namespace.all_projects.to_a).to match_array([project2, project1]) }
it { expect(child.all_projects.to_a).to match_array([project2]) }
context 'when recursive_namespace_lookup_as_inner_join feature flag is on' do
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
it 'queries for the namespace and its descendants' do
expect(Project).to receive(:where).with(namespace: [namespace, child])
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
namespace.all_projects
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