Commit 60f908a2 authored by Pavel Shutsin's avatar Pavel Shutsin

Merge branch 'jp-remove-sti-flag' into 'master'

Remove include_sti_condition flag

See merge request gitlab-org/gitlab!73734
parents eacb371a a4b4fbfe
......@@ -161,7 +161,7 @@ module Namespaces
def lineage(top: nil, bottom: nil, hierarchy_order: nil)
raise UnboundedSearch, 'Must bound search by either top or bottom' unless top || bottom
skope = self.class.without_sti_condition
skope = self.class
if top
skope = skope.where("traversal_ids @> ('{?}')", top.id)
......@@ -181,7 +181,6 @@ module Namespaces
# standard SELECT to avoid mismatched attribute errors when trying to
# chain future ActiveRelation commands, and retain the ordering.
skope = self.class
.without_sti_condition
.from(skope, self.class.table_name)
.select(skope.arel_table[Arel.star])
.order(depth: hierarchy_order)
......
......@@ -19,8 +19,7 @@ module Namespaces
return super unless use_traversal_ids_for_ancestor_scopes?
records = unscoped
.without_sti_condition
.where(id: without_sti_condition.select('unnest(traversal_ids)'))
.where(id: select('unnest(traversal_ids)'))
.order_by_depth(hierarchy_order)
.normal_select
......@@ -60,16 +59,6 @@ module Namespaces
end
end
# Make sure we drop the STI `type = 'Group'` condition for better performance.
# Logically equivalent so long as hierarchies remain homogeneous.
def without_sti_condition
if Feature.enabled?(:include_sti_condition, default_enabled: :yaml)
all
else
unscope(where: :type)
end
end
def order_by_depth(hierarchy_order)
return all unless hierarchy_order
......@@ -85,7 +74,7 @@ module Namespaces
# When we have queries that break this SELECT * format we can run in to errors.
# For example `SELECT DISTINCT on(...)` will fail when we chain a `.count` c
def normal_select
unscoped.without_sti_condition.from(all, :namespaces)
unscoped.from(all, :namespaces)
end
private
......@@ -108,7 +97,6 @@ module Namespaces
namespaces = Arel::Table.new(:namespaces)
records = unscoped
.without_sti_condition
.with(cte.to_arel)
.from([cte.table, namespaces])
......@@ -136,7 +124,6 @@ module Namespaces
base_ids = select(:id)
records = unscoped
.without_sti_condition
.from("namespaces, (#{base_ids.to_sql}) base")
.where('namespaces.traversal_ids @> ARRAY[base.id]')
......
---
name: include_sti_condition
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/72119
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343412
milestone: '14.5'
type: development
group: group::workspace
default_enabled: false
......@@ -571,16 +571,6 @@ RSpec.describe Group do
it 'filters out project namespace' do
expect(group.descendants.find_by_id(project_namespace.id)).to be_nil
end
context 'when include_sti_condition is disabled' do
before do
stub_feature_flags(include_sti_condition: false)
end
it 'raises an exception' do
expect { group.descendants.find_by_id(project_namespace.id)}.to raise_error(ActiveRecord::SubclassNotFound)
end
end
end
end
end
......
......@@ -25,26 +25,6 @@ RSpec.shared_examples 'namespace traversal scopes' do
it { is_expected.to contain_exactly(group_1.id, group_2.id) }
end
describe '.without_sti_condition' do
subject { described_class.where(type: 'Group').without_sti_condition }
context 'when include_sti_condition is enabled' do
before do
stub_feature_flags(include_sti_condition: true)
end
it { expect(subject.where_values_hash).to have_key('type') }
end
context 'when include_sti_condition is disabled' do
before do
stub_feature_flags(include_sti_condition: false)
end
it { expect(subject.where_values_hash).not_to have_key('type') }
end
end
describe '.order_by_depth' do
subject { described_class.where(id: [group_1, nested_group_1, deep_nested_group_1]).order_by_depth(direction) }
......
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