Introduce linear descendants feature flag

parent fb0c3d82
...@@ -53,7 +53,7 @@ module Namespaces ...@@ -53,7 +53,7 @@ module Namespaces
end end
def self_and_descendants(include_self: true) def self_and_descendants(include_self: true)
return super unless use_traversal_ids? return super unless use_traversal_ids_for_descendants_scopes?
if Feature.enabled?(:traversal_ids_btree, default_enabled: :yaml) if Feature.enabled?(:traversal_ids_btree, default_enabled: :yaml)
self_and_descendants_with_comparison_operators(include_self: include_self) self_and_descendants_with_comparison_operators(include_self: include_self)
...@@ -65,7 +65,7 @@ module Namespaces ...@@ -65,7 +65,7 @@ module Namespaces
end end
def self_and_descendant_ids(include_self: true) def self_and_descendant_ids(include_self: true)
return super unless use_traversal_ids? return super unless use_traversal_ids_for_descendants_scopes?
if Feature.enabled?(:traversal_ids_btree, default_enabled: :yaml) if Feature.enabled?(:traversal_ids_btree, default_enabled: :yaml)
self_and_descendants_with_comparison_operators(include_self: include_self).as_ids self_and_descendants_with_comparison_operators(include_self: include_self).as_ids
...@@ -109,6 +109,11 @@ module Namespaces ...@@ -109,6 +109,11 @@ module Namespaces
use_traversal_ids? use_traversal_ids?
end end
def use_traversal_ids_for_descendants_scopes?
Feature.enabled?(:use_traversal_ids_for_descendants_scopes, default_enabled: :yaml) &&
use_traversal_ids?
end
def self_and_descendants_with_comparison_operators(include_self: true) def self_and_descendants_with_comparison_operators(include_self: true)
base = all.select( base = all.select(
:traversal_ids, :traversal_ids,
......
---
name: use_traversal_ids_for_descendants_scopes
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/78542
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/350637
milestone: '14.8'
type: development
group: group::authentication and authorization
default_enabled: true
...@@ -361,6 +361,66 @@ RSpec.describe Namespace do ...@@ -361,6 +361,66 @@ RSpec.describe Namespace do
context 'linear' do context 'linear' do
it_behaves_like 'namespace traversal scopes' it_behaves_like 'namespace traversal scopes'
end end
shared_examples 'makes recursive queries' do
specify do
expect { subject }.to make_queries_matching(/WITH RECURSIVE/)
end
end
shared_examples 'does not make recursive queries' do
specify do
expect { subject }.not_to make_queries_matching(/WITH RECURSIVE/)
end
end
describe '.self_and_descendants' do
let_it_be(:namespace) { create(:namespace) }
subject { described_class.where(id: namespace).self_and_descendants.load }
it_behaves_like 'does not make recursive queries'
context 'when feature flag :use_traversal_ids is disabled' do
before do
stub_feature_flags(use_traversal_ids: false)
end
it_behaves_like 'makes recursive queries'
end
context 'when feature flag :use_traversal_ids_for_descendants_scopes is disabled' do
before do
stub_feature_flags(use_traversal_ids_for_descendants_scopes: false)
end
it_behaves_like 'makes recursive queries'
end
end
describe '.self_and_descendant_ids' do
let_it_be(:namespace) { create(:namespace) }
subject { described_class.where(id: namespace).self_and_descendant_ids.load }
it_behaves_like 'does not make recursive queries'
context 'when feature flag :use_traversal_ids is disabled' do
before do
stub_feature_flags(use_traversal_ids: false)
end
it_behaves_like 'makes recursive queries'
end
context 'when feature flag :use_traversal_ids_for_descendants_scopes is disabled' do
before do
stub_feature_flags(use_traversal_ids_for_descendants_scopes: false)
end
it_behaves_like 'makes recursive queries'
end
end
end end
context 'traversal_ids on create' do context 'traversal_ids on create' do
......
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