perf: avoid cloning when checking access

This commit is contained in:
Radical 2025-05-01 20:12:02 +02:00
parent 7b86706793
commit 2864196584
2 changed files with 3 additions and 3 deletions

View file

@ -15,10 +15,10 @@ pub fn web() -> Scope {
.service(refresh::res)
}
pub async fn check_access_token(access_token: String, pool: sqlx::Pool<Postgres>) -> Result<Uuid, HttpResponse> {
pub async fn check_access_token<'a>(access_token: String, pool: &'a sqlx::Pool<Postgres>) -> Result<Uuid, HttpResponse> {
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;

View file

@ -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::<AuthenticationRequest>(&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())