Skip to content

Commit

Permalink
fix: adding the pg_lock for the token
Browse files Browse the repository at this point in the history
  • Loading branch information
geekbrother committed Dec 13, 2023
1 parent 3fca011 commit 672b140
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/stores/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ impl ClientStore for sqlx::PgPool {

let mut transaction = self.begin().await?;

// Statement for locking to prevent an issue #230
// Statement for locking based on the client id to prevent an issue #230
sqlx::query("SELECT pg_advisory_xact_lock(abs(hashtext($1::text)))")
.bind(id)
.execute(&mut transaction)
.await?;

// Statement for locking based on the token to prevent an issue #292
sqlx::query("SELECT pg_advisory_xact_lock(abs(hashtext($1::text)))")
.bind(client.token.clone())
.execute(&mut transaction)
.await?;

sqlx::query("DELETE FROM public.clients WHERE id = $1 OR device_token = $2")
.bind(id)
.bind(client.token.clone())
Expand Down

0 comments on commit 672b140

Please sign in to comment.