Lookup usernames case insensitively

This commit is contained in:
Quentin Gliech
2025-04-10 14:23:41 +02:00
parent 4175e2ac85
commit 7f0dcaa73f
4 changed files with 14 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT user_id\n , username\n , created_at\n , locked_at\n , deactivated_at\n , can_request_admin\n FROM users\n WHERE username = $1\n ",
"query": "\n SELECT user_id\n , username\n , created_at\n , locked_at\n , deactivated_at\n , can_request_admin\n FROM users\n WHERE LOWER(username) = LOWER($1)\n ",
"describe": {
"columns": [
{
@@ -48,5 +48,5 @@
false
]
},
"hash": "48213d718a256a12540c0aec595ca3e436be423f2d0c868700c6397745ed0455"
"hash": "d2a4f5c01603463b78198529d295f7f121769ea5730d01c20c0ddbcdc79a5716"
}

View File

@@ -0,0 +1,10 @@
-- no-transaction
-- Copyright 2025 New Vector Ltd.
--
-- SPDX-License-Identifier: AGPL-3.0-only
-- Please see LICENSE in the repository root for full details.
-- Create an index on the username column, lower-cased, so that we can lookup
-- usernames in a case-insensitive manner.
CREATE INDEX CONCURRENTLY users_lower_username_idx
ON users (LOWER(username));

View File

@@ -175,7 +175,7 @@ impl UserRepository for PgUserRepository<'_> {
, deactivated_at
, can_request_admin
FROM users
WHERE username = $1
WHERE LOWER(username) = LOWER($1)
"#,
username,
)

View File

@@ -155,7 +155,7 @@ pub trait UserRepository: Send + Sync {
/// Returns [`Self::Error`] if the underlying repository fails
async fn lookup(&mut self, id: Ulid) -> Result<Option<User>, Self::Error>;
/// Find a [`User`] by its username
/// Find a [`User`] by its username, in a case-insensitive manner
///
/// Returns `None` if no [`User`] was found
///