Relationships
#5249 Index user.role so the admin queries stop scanning the whole user collection
Opened by skunk-ape · 11/30/2026
The three admin reads on the user collection filter on role, which has no index, so each one reads every user: listAllAdmins ({role: admin}), listAdminUsers ({role: admin, banned not true}) and listAdminSecondFactorStatus (a comma-boundary regex on role, added for swamp-club#5242). They run on cold admin paths today (the Roles tab, the last-admin guard in role changes), but the cost grows with signups, not with the number of admins, and none sets maxTimeMS.
Done when: a {role: 1} index exists, built through a migration with ensureIndex; listAdminSecondFactorStatus prefilters with something the index can serve (for example role in [admin, a regex anchored at the start of the field, a regex for a comma followed by admin]) and keeps holdsAdminAuthority as the real check; the three reads carry a maxTimeMS; and an explain on a seeded database shows IXSCAN, not COLLSCAN, for all three.
Open
No activity in this phase yet.
Sign in to post a ripple.