Skip to content

Commit

Permalink
Prevent user pref races (#1576)
Browse files Browse the repository at this point in the history
prevent user pref races
  • Loading branch information
dholms authored Sep 12, 2023
1 parent 6f41979 commit 1053c6f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/pds/src/services/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 1053c6f

Please sign in to comment.