Include nested subgroups in groups' children.json when active is false
What does this MR do and why?
Extends the /groups/.../-/children.json?active=false endpoint to also search for nested descendants.
- When
active=true, return active direct children. - When
active=false, return inactive descendants.- If a lower-level descendant is matched and it has other ancestors. Include their inactive ancestors.
This MR also adds a upto_preloaded_ancestors_only option in the GroupDescendant concern. This allows us to bypass the N+1 check and only build the hierarchy strictly using the preloaded groups.
This is behind a WIP feature flag group_descendants_active_filter because the feature is still incomplete. We need to update the logic behind children_count to respect the group/project's inactive status.
Query Plans
{ active: true }
Group Load/Count is inherently slow (>1s), here is the query plan without the
activeparam.
- Group Load: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/39862/commands/123003
- Group Count: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/39863/commands/123007
- Project Load: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/39863/commands/123013
- Project Count: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/39863/commands/123015
{ active: false }
Setup:
exec UPDATE namespace_settings SET archived = true WHERE namespace_id IN (SELECT namespace_settings.namespace_id FROM namespace_settings JOIN namespaces ON namespaces.id = namespace_settings.namespace_id WHERE namespaces.traversal_ids[1] = 9970 AND namespaces.id != 9970 ORDER BY random() LIMIT 500);
exec VACUUM ANALYZE namespace_settings
Group Load/Count is inherently slow (>1s), here is the query plan without the
activeparam.
- Group Load: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/40201/commands/123718
- Group Count: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/40201/commands/123723
Project Load query plan without the inactive filters is already at (~746ms)
- Project Load: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/39863/commands/123026
- Project Count: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/39863/commands/123029
- Group Ancestors Load: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/40201/commands/123736
References
Related to #538563 (closed)
Screenshots or screen recordings
N/A
How to set up and validate locally
- Enable the
group_descendants_active_filterfeature flag in the rails console:Feature.enable(:group_descendants_active_filter) - Create a group with subgroups and projects that are marked for deletion or archived.
- Groups and projects can be marked for deletion in `Settings > General > Advanced Settings`
- Projects can also be archived in
Settings > General
- Group archiving is still WiP and there's no UI for it. We could archived groups by updating
group.namespace_settings.archived=truein the rails console.
- Go to
http://localhost:3000/groups/<group-name>/-/children.json?active=falseto get all inactive descendants. - Go to
http://localhost:3000/groups/<group-name>/-/children.json?active=trueto get all active descendants.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
