From 33d4454c68b69609a8fbffdfb40ea073a9bfb772 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Sun, 24 Mar 2024 20:18:34 +0100 Subject: [PATCH] opt(sql): added 'LIMIT 1' to SELECT queries, that fetch only one item --- src/backend/tokens.rs | 4 ++-- src/backend/user.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/tokens.rs b/src/backend/tokens.rs index f660164..a897a70 100644 --- a/src/backend/tokens.rs +++ b/src/backend/tokens.rs @@ -19,7 +19,7 @@ impl Backend { ) -> anyhow::Result> { match sqlx::query_as!( AuthTokensRow, - r#"SELECT * FROM AuthTokens WHERE token = ?;"#, + r#"SELECT * FROM AuthTokens WHERE token = ? LIMIT 1;"#, token ) .fetch_one(&self.pool) @@ -49,7 +49,7 @@ impl Backend { ) -> anyhow::Result> { match sqlx::query_as!( InviteTokensRow, - r#"SELECT * FROM InviteTokens WHERE token = ?;"#, + r#"SELECT * FROM InviteTokens WHERE token = ? LIMIT 1;"#, token ) .fetch_one(&self.pool) diff --git a/src/backend/user.rs b/src/backend/user.rs index 48e4b7c..a9160d0 100644 --- a/src/backend/user.rs +++ b/src/backend/user.rs @@ -90,7 +90,7 @@ impl Backend { async fn get_user(&self, userid: Uuid) -> Result> { match sqlx::query_as!( UsersRow, - r#"SELECT * FROM Users WHERE userid = ?;"#, + r#"SELECT * FROM Users WHERE userid = ? LIMIT 1;"#, userid.as_bytes().as_slice() ) .fetch_one(&self.pool)