Commit 865cff24 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch '339194-fj-use-group-ancestors-linear-scopes' into 'master'

Replace Group ancestors scope with linear version

See merge request gitlab-org/gitlab!70495
parents d1948d0a bd908d32
......@@ -192,9 +192,15 @@ class Group < Namespace
# Returns the ids of the passed group models where the `emails_disabled`
# column is set to true anywhere in the ancestor hierarchy.
def ids_with_disabled_email(groups)
innner_query = Gitlab::ObjectHierarchy
.new(Group.where('id = namespaces_with_emails_disabled.id'))
.base_and_ancestors
inner_groups = Group.where('id = namespaces_with_emails_disabled.id')
inner_ancestors = if Feature.enabled?(:linear_group_ancestor_scopes, default_enabled: :yaml)
inner_groups.self_and_ancestors
else
Gitlab::ObjectHierarchy.new(inner_groups).base_and_ancestors
end
inner_query = inner_ancestors
.where(emails_disabled: true)
.select('1')
.limit(1)
......@@ -202,7 +208,7 @@ class Group < Namespace
group_ids = Namespace
.from('(SELECT * FROM namespaces) as namespaces_with_emails_disabled')
.where(namespaces_with_emails_disabled: { id: groups })
.where('EXISTS (?)', innner_query)
.where('EXISTS (?)', inner_query)
.pluck(:id)
Set.new(group_ids)
......
---
name: linear_group_ancestor_scopes
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/70495
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/341115
milestone: '14.4'
type: development
group: group::access
default_enabled: false
......@@ -2608,17 +2608,29 @@ RSpec.describe Group do
end
describe '.ids_with_disabled_email' do
let!(:parent_1) { create(:group, emails_disabled: true) }
let!(:child_1) { create(:group, parent: parent_1) }
let_it_be(:parent_1) { create(:group, emails_disabled: true) }
let_it_be(:child_1) { create(:group, parent: parent_1) }
let!(:parent_2) { create(:group, emails_disabled: false) }
let!(:child_2) { create(:group, parent: parent_2) }
let_it_be(:parent_2) { create(:group, emails_disabled: false) }
let_it_be(:child_2) { create(:group, parent: parent_2) }
let!(:other_group) { create(:group, emails_disabled: false) }
let_it_be(:other_group) { create(:group, emails_disabled: false) }
subject(:group_ids_where_email_is_disabled) { described_class.ids_with_disabled_email([child_1, child_2, other_group]) }
shared_examples 'returns namespaces with disabled email' do
subject(:group_ids_where_email_is_disabled) { described_class.ids_with_disabled_email([child_1, child_2, other_group]) }
it { is_expected.to eq(Set.new([child_1.id])) }
it { is_expected.to eq(Set.new([child_1.id])) }
end
it_behaves_like 'returns namespaces with disabled email'
context 'when feature flag :linear_group_ancestor_scopes is disabled' do
before do
stub_feature_flags(linear_group_ancestor_scopes: false)
end
it_behaves_like 'returns namespaces with disabled email'
end
end
describe '.timelogs' 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