Add new fields to GroupType
What does this MR do and why?
This MR reinstates !139226 (merged) which was reverted before the N+1 queries spec was failing on master #420702 (comment 1696780490). The spec has been fixed in this MR by ignoring the auth queries.
This is part of the ongoing Organization work by the grouptenant scale group. Read the blueprint to learn more https://docs.gitlab.com/ee/architecture/blueprints/organization/index.html.
Fields introduced are:
- descendantGroupsCount
- groupMembersCount
- projectsCount
Query plans
Raw Query
SELECT COUNT(projects) AS "count_projects", "namespaces"."id" AS "namespaces_id"
FROM "namespaces"
LEFT OUTER JOIN "projects" ON "projects"."archived" != TRUE AND "projects"."namespace_id" = "namespaces"."id"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."id" IN
(1755573, 1761696, 1793858, 1819570, 1920469, 2287432, 2351283, 2452873, 2593421, 2639717, 2750817, 2843837,
2907304, 3345373, 3455548, 3887963, 3910297, 3925021, 3930213, 3952433)
GROUP BY "namespaces"."id";
Raw Query
SELECT COUNT(members) AS "count_members", "namespaces"."id" AS "namespaces_id"
FROM "namespaces"
LEFT OUTER JOIN "members" ON "members"."source_type" = 'Namespace' AND "members"."requested_at" IS NULL AND
"members"."access_level" != 5 AND "members"."source_id" = "namespaces"."id" AND
"members"."type" = 'GroupMember'
WHERE "namespaces"."type" = 'GROUP'
AND "namespaces"."id" IN
(1755573, 1761696, 1793858, 1819570, 1920469, 2287432, 2351283, 2452873, 2593421, 2639717, 2750817, 2843837,
2907304, 3345373, 3455548, 3887963, 3910297, 3925021, 3930213, 3952433)
GROUP BY "namespaces"."id";
Raw Query
SELECT COUNT(children_namespaces) AS "count_children_namespaces", "namespaces"."id" AS "namespaces_id"
FROM "namespaces"
LEFT OUTER JOIN "namespaces" "children_namespaces" ON "children_namespaces"."type" = 'Group' AND
"children_namespaces"."parent_id" = "namespaces"."id"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."id" IN
(1755573, 1761696, 1793858, 1819570, 1920469, 2287432, 2351283, 2452873, 2593421, 2639717, 2750817, 2843837,
2907304, 3345373, 3455548, 3887963, 3910297, 3925021, 3930213, 3952433)
GROUP BY "namespaces"."id";
How to set up and validate locally
Run the following query on GraphiQL https://gdk.test:3000/-/graphql-explorer:
Query
{
organization(id: "gid://gitlab/Organizations::Organization/1") {
id
path
groups(sort: NAME_DESC) {
edges {
node {
id
descendantGroupsCount
groupMembersCount
projectsCount
}
}
}
}
}
Output
{
"data": {
"organization": {
"id": "gid://gitlab/Organizations::Organization/1",
"path": "default",
"groups": {
"edges": [
{
"node": {
"id": "gid://gitlab/Group/35",
"descendantGroupsCount": 0,
"groupMembersCount": 5,
"projectsCount": 2
}
},
{
"node": {
"id": "gid://gitlab/Group/31",
"descendantGroupsCount": 0,
"groupMembersCount": 5,
"projectsCount": 1
}
},
{
"node": {
"id": "gid://gitlab/Group/27",
"descendantGroupsCount": 0,
"groupMembersCount": 5,
"projectsCount": 1
}
},
{
"node": {
"id": "gid://gitlab/Group/24",
"descendantGroupsCount": 0,
"groupMembersCount": 4,
"projectsCount": 2
}
},
{
"node": {
"id": "gid://gitlab/Group/33",
"descendantGroupsCount": 0,
"groupMembersCount": 5,
"projectsCount": 1
}
},
{
"node": {
"id": "gid://gitlab/Group/29",
"descendantGroupsCount": 0,
"groupMembersCount": 5,
"projectsCount": 1
}
},
{
"node": {
"id": "gid://gitlab/Group/109",
"descendantGroupsCount": 0,
"groupMembersCount": 1,
"projectsCount": 0
}
},
{
"node": {
"id": "gid://gitlab/Group/110",
"descendantGroupsCount": 0,
"groupMembersCount": 1,
"projectsCount": 0
}
},
{
"node": {
"id": "gid://gitlab/Group/108",
"descendantGroupsCount": 1,
"groupMembersCount": 1,
"projectsCount": 0
}
},
{
"node": {
"id": "gid://gitlab/Group/107",
"descendantGroupsCount": 2,
"groupMembersCount": 1,
"projectsCount": 0
}
}
]
}
}
}
}
Related to #420702 (closed)
Edited by Abdul Wadood