From 672b14066e10a70f00e8b1aa012ad31962ab5aac Mon Sep 17 00:00:00 2001 From: Max Kalashnikoff Date: Wed, 13 Dec 2023 12:44:26 +0100 Subject: [PATCH] fix: adding the pg_lock for the token --- src/stores/client.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/stores/client.rs b/src/stores/client.rs index 7140a7c9..b19cdb05 100644 --- a/src/stores/client.rs +++ b/src/stores/client.rs @@ -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())