Skip to content

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

  1. Seed 1k groups owned by a user (example script - https://gitlab.com/-/snippets/2042155)
  2. Go to the user's page as an admin and observe:

image

With 1k queries like:

image

An Ultimate customer with 12.000 seats ran into timeouts on the admin page for a user owning ~16k groups.