Use linear version of groups_including_descendants_by

Changelog: performance
parent 72f0f338
......@@ -823,9 +823,15 @@ class Group < Namespace
end
def self.groups_including_descendants_by(group_ids)
Gitlab::ObjectHierarchy
.new(Group.where(id: group_ids))
groups = Group.where(id: group_ids)
if Feature.enabled?(:linear_group_including_descendants_by, default_enabled: :yaml)
groups.self_and_descendants
else
Gitlab::ObjectHierarchy
.new(groups)
.base_and_descendants
end
end
def disable_shared_runners!
......
---
name: linear_group_including_descendants_by
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68835
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339431
milestone: '14.3'
type: development
group: group::access
default_enabled: false
......@@ -2274,19 +2274,27 @@ RSpec.describe Group do
end
describe '.groups_including_descendants_by' do
it 'returns the expected groups for a group and its descendants' do
parent_group1 = create(:group)
child_group1 = create(:group, parent: parent_group1)
child_group2 = create(:group, parent: parent_group1)
let_it_be(:parent_group1) { create(:group) }
let_it_be(:parent_group2) { create(:group) }
let_it_be(:extra_group) { create(:group) }
let_it_be(:child_group1) { create(:group, parent: parent_group1) }
let_it_be(:child_group2) { create(:group, parent: parent_group1) }
let_it_be(:child_group3) { create(:group, parent: parent_group2) }
parent_group2 = create(:group)
child_group3 = create(:group, parent: parent_group2)
subject { described_class.groups_including_descendants_by([parent_group2.id, parent_group1.id]) }
create(:group)
shared_examples 'returns the expected groups for a group and its descendants' do
specify { is_expected.to contain_exactly(parent_group1, parent_group2, child_group1, child_group2, child_group3) }
end
it_behaves_like 'returns the expected groups for a group and its descendants'
groups = described_class.groups_including_descendants_by([parent_group2.id, parent_group1.id])
context 'when :linear_group_including_descendants_by feature flag is disabled' do
before do
stub_feature_flags(linear_group_including_descendants_by: false)
end
expect(groups).to contain_exactly(parent_group1, parent_group2, child_group1, child_group2, child_group3)
it_behaves_like 'returns the expected groups for a group and its descendants'
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