Commit c5b74ffd authored by Tetiana Chupryna's avatar Tetiana Chupryna

Merge branch '324748-replace-namespace-self_and_hierarchy-with-linear-version' into 'master'

Replace Namespace#self_and_hierarchy with linear version

See merge request gitlab-org/gitlab!76814
parents 6ad0d8ab 0a544f14
......@@ -57,6 +57,13 @@ module Namespaces
traversal_ids.present?
end
def use_traversal_ids_for_self_and_hierarchy?
return false unless use_traversal_ids?
return false unless Feature.enabled?(:use_traversal_ids_for_self_and_hierarchy, root_ancestor, default_enabled: :yaml)
traversal_ids.present?
end
def use_traversal_ids_for_ancestors?
return false unless use_traversal_ids?
return false unless Feature.enabled?(:use_traversal_ids_for_ancestors, root_ancestor, default_enabled: :yaml)
......@@ -107,6 +114,12 @@ module Namespaces
self_and_descendants.where.not(id: id)
end
def self_and_hierarchy
return super unless use_traversal_ids_for_self_and_hierarchy?
self_and_descendants.or(ancestors)
end
def ancestors(hierarchy_order: nil)
return super unless use_traversal_ids_for_ancestors?
......
---
name: use_traversal_ids_for_self_and_hierarchy
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/76814
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/348527
milestone: '14.7'
type: development
group: group::workspace
default_enabled: false
......@@ -503,6 +503,10 @@ RSpec.describe Group do
it { expect(group.descendants.to_sql).not_to include 'traversal_ids @>' }
end
describe '#self_and_hierarchy' do
it { expect(group.self_and_hierarchy.to_sql).not_to include 'traversal_ids @>' }
end
describe '#ancestors' do
it { expect(group.ancestors.to_sql).not_to include 'traversal_ids <@' }
end
......@@ -527,6 +531,10 @@ RSpec.describe Group do
it { expect(group.descendants.to_sql).to include 'traversal_ids @>' }
end
describe '#self_and_hierarchy' do
it { expect(group.self_and_hierarchy.to_sql).to include 'traversal_ids @>' }
end
describe '#ancestors' do
it { expect(group.ancestors.to_sql).to include "\"namespaces\".\"id\" = #{group.parent_id}" }
......
......@@ -1263,6 +1263,32 @@ RSpec.describe Namespace do
end
end
describe '#use_traversal_ids_for_self_and_hierarchy?' do
let_it_be(:namespace, reload: true) { create(:namespace) }
subject { namespace.use_traversal_ids_for_self_and_hierarchy? }
it { is_expected.to eq true }
it_behaves_like 'disabled feature flag when traversal_ids is blank'
context 'when use_traversal_ids_for_self_and_hierarchy feature flag is false' do
before do
stub_feature_flags(use_traversal_ids_for_self_and_hierarchy: false)
end
it { is_expected.to eq false }
end
context 'when use_traversal_ids? feature flag is false' do
before do
stub_feature_flags(use_traversal_ids: false)
end
it { is_expected.to eq false }
end
end
describe '#users_with_descendants' do
let(:user_a) { create(:user) }
let(:user_b) { create(:user) }
......
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