N+1 in getting user solo owned groups
Summary
solo_owned_groups
in the User model generates additional queries for each owned group. This is being used in multiple places, such as Users::DestroyService
, User#can_be_removed?
, users' profile and admin users views.
Steps to reproduce
- Seed 1k groups owned by a user (example script - https://gitlab.com/-/snippets/2042155)
- Go to the user's page as an admin and observe:
With 1k queries like:
An Ultimate customer with 12.000 seats ran into timeouts on the admin page for a user owning ~16k groups.