Skip to content

Commit

Permalink
fix: adding the pg_lock for the token (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
geekbrother committed Dec 13, 2023
1 parent 3fca011 commit d77fa50
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/stores/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ impl ClientStore for sqlx::PgPool {

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

// Statement for locking 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 client id to prevent an issue #230
// and locking based on the token to prevent an issue #292
sqlx::query(
"SELECT
pg_advisory_xact_lock(abs(hashtext($1::text))),
pg_advisory_xact_lock(abs(hashtext($2::text)))",
)
.bind(id)
.bind(client.token.clone())
.execute(&mut transaction)
.await?;

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

0 comments on commit d77fa50

Please sign in to comment.