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.

  1. When active=true, return active direct children.
  2. 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.

image

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 active param.

{ 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 active param.

Project Load query plan without the inactive filters is already at (~746ms)

References

Related to #538563 (closed)

Screenshots or screen recordings

N/A

How to set up and validate locally

  1. Enable the group_descendants_active_filter feature flag in the rails console: Feature.enable(:group_descendants_active_filter)
  2. 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=true in the rails console.
  3. Go to http://localhost:3000/groups/<group-name>/-/children.json?active=false to get all inactive descendants.
  4. Go to http://localhost:3000/groups/<group-name>/-/children.json?active=true to 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.

Edited by Shane Maglangit

Merge request reports

Loading