Commit 466cf5fd authored by charlie ablett's avatar charlie ablett

Merge branch '341823_exclude_prpoject_namesapce_from_loaded_in_group_list' into 'master'

Exclude project namespace when computing subgroup counts

See merge request gitlab-org/gitlab!73305
parents efa5169e 9f1d766a
...@@ -41,9 +41,11 @@ module LoadedInGroupList ...@@ -41,9 +41,11 @@ module LoadedInGroupList
namespaces = Namespace.arel_table namespaces = Namespace.arel_table
children = namespaces.alias('children') children = namespaces.alias('children')
# TODO 6473: remove the filtering of the Namespaces::ProjectNamespace see https://gitlab.com/groups/gitlab-org/-/epics/6473
namespaces.project(Arel.star.count.as('preloaded_subgroup_count')) namespaces.project(Arel.star.count.as('preloaded_subgroup_count'))
.from(children) .from(children)
.where(children[:parent_id].eq(namespaces[:id])) .where(children[:parent_id].eq(namespaces[:id]))
.where(children[:type].is_distinct_from(Namespaces::ProjectNamespace.sti_name))
end end
def member_count_sql def member_count_sql
......
...@@ -3,49 +3,67 @@ ...@@ -3,49 +3,67 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe LoadedInGroupList do RSpec.describe LoadedInGroupList do
let(:parent) { create(:group) } let_it_be(:parent) { create(:group) }
let_it_be(:group) { create(:group, parent: parent) }
let_it_be(:project) { create(:project, namespace: parent) }
subject(:found_group) { Group.with_selects_for_list.find_by(id: parent.id) } let(:archived_parameter) { nil }
describe '.with_selects_for_list' do before do
it 'includes the preloaded counts for groups' do
create(:group, parent: parent)
create(:project, namespace: parent)
parent.add_developer(create(:user)) parent.add_developer(create(:user))
end
found_group = Group.with_selects_for_list.find_by(id: parent.id) subject(:found_group) { Group.with_selects_for_list(archived: archived_parameter).find_by(id: parent.id) }
describe '.with_selects_for_list' do
it 'includes the preloaded counts for groups' do
expect(found_group.preloaded_project_count).to eq(1) expect(found_group.preloaded_project_count).to eq(1)
expect(found_group.preloaded_subgroup_count).to eq(1) expect(found_group.preloaded_subgroup_count).to eq(1)
expect(found_group.preloaded_member_count).to eq(1) expect(found_group.preloaded_member_count).to eq(1)
end end
context 'with project namespaces' do
let_it_be(:group1) { create(:group, parent: parent) }
let_it_be(:group2) { create(:group, parent: parent) }
let_it_be(:project_namespace) { create(:project_namespace, project: project) }
it 'does not include project_namespaces in the count of subgroups' do
expect(found_group.preloaded_subgroup_count).to eq(3)
expect(parent.subgroup_count).to eq(3)
end
end
context 'with archived projects' do context 'with archived projects' do
it 'counts including archived projects when `true` is passed' do let_it_be(:archived_project) { create(:project, namespace: parent, archived: true) }
create(:project, namespace: parent, archived: true)
create(:project, namespace: parent)
found_group = Group.with_selects_for_list(archived: 'true').find_by(id: parent.id) let(:archived_parameter) { true }
it 'counts including archived projects when `true` is passed' do
expect(found_group.preloaded_project_count).to eq(2) expect(found_group.preloaded_project_count).to eq(2)
end end
it 'counts only archived projects when `only` is passed' do context 'when not counting archived projects' do
create_list(:project, 2, namespace: parent, archived: true) let(:archived_parameter) { false }
create(:project, namespace: parent)
it 'counts projects without archived ones' do
expect(found_group.preloaded_project_count).to eq(1)
end
end
context 'with archived only' do
let_it_be(:archived_project2) { create(:project, namespace: parent, archived: true) }
found_group = Group.with_selects_for_list(archived: 'only').find_by(id: parent.id) let(:archived_parameter) { 'only' }
it 'counts only archived projects when `only` is passed' do
expect(found_group.preloaded_project_count).to eq(2) expect(found_group.preloaded_project_count).to eq(2)
end end
end end
end end
end
describe '#children_count' do describe '#children_count' do
it 'counts groups and projects' do it 'counts groups and projects' do
create(:group, parent: parent)
create(:project, namespace: parent)
expect(found_group.children_count).to eq(2) expect(found_group.children_count).to eq(2)
end end
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