Skip to content

Make the admin Roles page fast with an indexed has_roles column - #13171

Merged
iHiD merged 2 commits into
mainfrom
roles-page-index
Nov 26, 2026
Merged

iHiD merged 2 commits into
mainfrom
roles-page-index

Conversation

@iHiD

@iHiD iHiD commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

The admin Roles page at /admin/roles hangs in production. This PR makes it load straight away.

To find the users with a role, the page asked MySQL for every user_data row with JSON_LENGTH(roles) > 0. No index can answer that, so MySQL read all 3 million rows on every page load, and again to count them for the pagination.

user_data now has a has_roles column. MySQL fills it in from roles, and it has an index. User::RetrieveRoleHolders filters on it, so MySQL now reads only the 601 users who have a role. The filter by one role still uses JSON_CONTAINS, but only on those rows.

Production already has the column and its index. Both were added by hand on 2026-11-26, as an instant column change and an online index build. Like the other migrations, this one returns early in production, and it adds the column and index in development and test. Rails 7.2 leaves generated columns out of INSERTs and UPDATEs, so saving a user is unaffected.

🤖 Generated with Claude Code

iHiD and others added 2 commits November 26, 2026 18:03
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…test requires

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iHiD
iHiD merged commit 7363bbf into main Nov 26, 2026
31 checks passed
@iHiD
iHiD deleted the roles-page-index branch November 26, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant