mirror of
https://github.com/element-hq/synapse.git
synced 2026-11-04 09:07:22 +00:00
Checking whether a username is available looks users up case-insensitively, with `WHERE lower(name) = lower(?)`. But there is currently no index on `lower(name)`, so each check scans the whole table. This backs registration, `GET /_synapse/admin/v1/username_available` and `GET /_synapse/mas/is_localpart_available`, which Matrix Authentication Service will call as the user types in its registration form ([Interactive feedback for username availability in the registration form (element-hq/matrix-authentication-service#5977)](https://github.com/element-hq/matrix-authentication-service/pull/5977)). - Adds `users_lower_name` on `users (lower(name))`, built as a background update, on both PostgreSQL and SQLite. - matrix.org already has an index with this name and definition, created by hand ([Postgres indexes differ on matrix.org (matrix-org/synapse#11893)](https://github.com/matrix-org/synapse/issues/11893)). The background update drops and rebuilds it concurrently rather than adding a duplicate; lookups fall back to a table scan until the rebuild finishes. ### Pull Request Checklist * [x] Pull request is based on the develop branch * [x] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). The entry should: - Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from `EventStore` to `EventWorkerStore`.". - Use markdown where necessary, mostly for `code blocks`. - End with either a period (.) or an exclamation mark (!). - Start with a capital letter. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [x] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters))