Skip to content

Commit

Permalink
chore: use functional mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed May 21, 2024
1 parent f7f260f commit 776802a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/stores/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,20 @@ impl ClientStore for sqlx::PgPool {
FOR UPDATE
";
let start = Instant::now();
let res = sqlx::query_as::<sqlx::postgres::Postgres, ClientSelect>(query)
let existing_client = sqlx::query_as::<sqlx::postgres::Postgres, ClientSelect>(query)
.bind(id)
.bind(client.token.clone())
.fetch_one(&mut transaction)
.await;
.await
.map(Some)
.or_else(|e| match e {
sqlx::Error::RowNotFound => Ok(None),
e => Err(e),
})?;
if let Some(metrics) = metrics {
metrics.postgres_query("create_client_delete", start);
}

let existing_client = match res {
Err(sqlx::Error::RowNotFound) => None,
Err(e) => return Err(e.into()),
Ok(row) => Some(row),
};

if let Some(existing_client) = existing_client {
if existing_client.id == id && existing_client.device_token != client.token {
let query = "
Expand Down

0 comments on commit 776802a

Please sign in to comment.