Use batched pre-drain in Groups::DestroyService

Summary

Apply the same batched pre-drain pattern to group destruction. Delete direct group children in committed batches before calling group.destroy!.

Context

Groups are simpler than projects. Most heavy data lives under projects, which are destroyed first. But direct group children (group_members, labels, milestones, boards, epics, namespace_settings) can still cause long transactions for large groups.

Requirements

  1. Pre-drain before destroy. Call BatchedPreDrain for the group's direct CASCADE FK children before calling group.destroy!.
  2. Register hooks for group children with side effects (e.g. avatar uploads).
  3. Re-enqueue on budget exhaustion. If the pre-drain returns :over_budget, re-enqueue the worker. The group stays marked for deletion. The next run continues.
  4. Destroy the group. Once the pre-drain finishes, call group.destroy! with minimal remaining cascade.
  5. Preserve existing ordering. The pre-drain must run after child projects are destroyed, matching the current destroy flow.

Specs

  • Pre-drain runs before destroy!
  • Worker re-enqueues on :over_budget
  • Re-runs after partial drain are idempotent
  • Correct ordering relative to child project destruction

Dependencies

Depends on the generic batched pre-drain helper (#619116).

References

Edited by 🤖 GitLab Bot 🤖