From 1829297133a299f40c57e0444728b715fb19ea9f Mon Sep 17 00:00:00 2001 From: dholms Date: Mon, 11 Sep 2023 14:27:07 -0500 Subject: [PATCH] prevent user pref races --- packages/pds/src/services/account/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/pds/src/services/account/index.ts b/packages/pds/src/services/account/index.ts index dd28af01df5..8173d9160af 100644 --- a/packages/pds/src/services/account/index.ts +++ b/packages/pds/src/services/account/index.ts @@ -590,6 +590,15 @@ export class AccountService { `Some preferences are not in the ${namespace} namespace`, ) } + // short-held row lock to prevent races + if (this.db.dialect === 'pg') { + await this.db.db + .selectFrom('user_account') + .selectAll() + .forUpdate() + .where('did', '=', did) + .executeTakeFirst() + } // get all current prefs for user and prep new pref rows const allPrefs = await this.db.db .selectFrom('user_pref')