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 ...@@ -261,13 +261,8 @@ 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
return Project.where(namespace: self) if user? namespace = user? ? self : self_and_descendants
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
......
---
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 ...@@ -13,12 +13,5 @@ class Analytics::DevopsAdoption::Segment < ApplicationRecord
scope :ordered_by_name, -> { includes(:namespace).order('"namespaces"."name" ASC') } scope :ordered_by_name, -> { includes(:namespace).order('"namespaces"."name" ASC') }
scope :for_namespaces, -> (namespaces) { where(namespace_id: namespaces) } scope :for_namespaces, -> (namespaces) { where(namespace_id: namespaces) }
scope :for_parent, -> (namespace) { scope :for_parent, -> (namespace) { for_namespaces(namespace.self_and_descendants) }
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
}
end end
...@@ -52,10 +52,6 @@ RSpec.describe Analytics::DevopsAdoption::Segment, type: :model do ...@@ -52,10 +52,6 @@ RSpec.describe Analytics::DevopsAdoption::Segment, type: :model do
subject(:segments) { described_class.for_parent(group) } 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 it 'selects segments for given namespace only' do
expect(segments).to match_array([segment1, segment2]) expect(segments).to match_array([segment1, segment2])
end end
......
...@@ -911,24 +911,10 @@ RSpec.describe Namespace do ...@@ -911,24 +911,10 @@ 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]) }
context 'when recursive_namespace_lookup_as_inner_join feature flag is on' do it 'queries for the namespace and its descendants' do
before do expect(Project).to receive(:where).with(namespace: [namespace, child])
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
context 'when recursive_namespace_lookup_as_inner_join feature flag is off' do namespace.all_projects
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