Skip to content

Commit

Permalink
fix(db): remove excessive row-locking
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiDood committed Aug 13, 2024
1 parent 0eb8173 commit e652eda
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions database/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export class Database implements Loggable {
@timed async getDesignatedSenderCredentials() {
const sql = this.#sql;
const [first, ...rest] =
await sql`SELECT email, given_name, family_name, access_token, refresh_token, expiration FROM drap.designated_sender JOIN drap.candidate_senders cs USING (email) JOIN drap.users USING (email) WHERE user_id IS NOT NULL AND is_admin AND lab_id IS NULL FOR UPDATE OF cs`;
await sql`SELECT email, given_name, family_name, access_token, refresh_token, expiration FROM drap.designated_sender JOIN drap.candidate_senders cs USING (email) JOIN drap.users USING (email) WHERE user_id IS NOT NULL AND is_admin AND lab_id IS NULL`;
strictEqual(rest.length, 0);
return typeof first === 'undefined' ? null : parse(DesignatedSenderCredentials, first);
}
Expand Down Expand Up @@ -629,15 +629,15 @@ export class Database implements Loggable {
@timed async getOneDraftNotification() {
const sql = this.#sql;
const [notif, ...rest] =
await sql`SELECT notif_id, draft_id, ty, round, dn.lab_id, lab_name, u.email, given_name, family_name FROM drap.draft_notifications dn LEFT JOIN drap.labs USING (lab_id) LEFT JOIN drap.users u USING (email) ORDER BY notif_id LIMIT 1 FOR UPDATE OF dn SKIP LOCKED`;
await sql`SELECT notif_id, draft_id, ty, round, dn.lab_id, lab_name, u.email, given_name, family_name FROM drap.draft_notifications dn LEFT JOIN drap.labs USING (lab_id) LEFT JOIN drap.users u USING (email) ORDER BY notif_id LIMIT 1 FOR UPDATE SKIP LOCKED`;
strictEqual(rest.length, 0);
return typeof notif === 'undefined' ? null : parse(DraftNotificationWithDetails, notif);
}

@timed async getOneUserNotification() {
const sql = this.#sql;
const [notif, ...rest] =
await sql`SELECT notif_id, dn.lab_id, lab_name, email, given_name, family_name FROM drap.user_notifications dn JOIN drap.labs USING (lab_id) JOIN drap.users USING (email) ORDER BY notif_id LIMIT 1 FOR UPDATE OF dn SKIP LOCKED`;
await sql`SELECT notif_id, dn.lab_id, lab_name, email, given_name, family_name FROM drap.user_notifications dn JOIN drap.labs USING (lab_id) JOIN drap.users USING (email) ORDER BY notif_id LIMIT 1 FOR UPDATE SKIP LOCKED`;
strictEqual(rest.length, 0);
return typeof notif === 'undefined' ? null : parse(UserNotificationWithDetails, notif);
}
Expand Down

0 comments on commit e652eda

Please sign in to comment.