Skip to content

Commit

Permalink
Prevent user pref races (bluesky-social#1576)
Browse files Browse the repository at this point in the history
prevent user pref races
  • Loading branch information
dholms authored and mloar committed Sep 25, 2023
1 parent 1a8dd27 commit 51002e3
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 51002e3

Please sign in to comment.