From 286419658447e31a98d40ce06d21bf807ee9361d Mon Sep 17 00:00:00 2001 From: Radical Date: Thu, 1 May 2025 20:12:02 +0200 Subject: [PATCH] perf: avoid cloning when checking access --- src/api/v1/auth/mod.rs | 4 ++-- src/api/v1/user.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/v1/auth/mod.rs b/src/api/v1/auth/mod.rs index 4cd06e7..8c38063 100644 --- a/src/api/v1/auth/mod.rs +++ b/src/api/v1/auth/mod.rs @@ -15,10 +15,10 @@ pub fn web() -> Scope { .service(refresh::res) } -pub async fn check_access_token(access_token: String, pool: sqlx::Pool) -> Result { +pub async fn check_access_token<'a>(access_token: String, pool: &'a sqlx::Pool) -> Result { match sqlx::query_as("SELECT CAST(uuid as VARCHAR), created FROM access_tokens WHERE token = $1") .bind(&access_token) - .fetch_one(&pool) + .fetch_one(&*pool) .await { Ok(row) => { let (uuid, created): (String, i64) = row; diff --git a/src/api/v1/user.rs b/src/api/v1/user.rs index 9287e1b..0d8b416 100644 --- a/src/api/v1/user.rs +++ b/src/api/v1/user.rs @@ -34,7 +34,7 @@ pub async fn res(mut payload: web::Payload, path: web::Path<(String,)>, data: we let authentication_request = serde_json::from_slice::(&body)?; - let authorized = check_access_token(authentication_request.access_token, data.pool.clone()).await; + let authorized = check_access_token(authentication_request.access_token, &data.pool).await; if authorized.is_err() { return Ok(authorized.unwrap_err())