Skip to content

Commit

Permalink
fix(autorecord): lock fetching to prevent multiple queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Apr 23, 2024
1 parent 4090922 commit 4bc5b4c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/bot/src/modules/autorecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface AutoRecordUpsert {
export default class AutorecordModule extends DexareModule<DexareClient<CraigBotConfig>> {
debounceTimeouts = new Map<string, any>();
autorecords = new Map<string, AutoRecord>();
fetching = false;
lastRefresh = 0;

constructor(client: any) {
Expand Down Expand Up @@ -56,6 +57,8 @@ export default class AutorecordModule extends DexareModule<DexareClient<CraigBot
}

async fetchAll() {
if (this.fetching) return;
this.fetching = true;
const autorecords = (
await prisma.autoRecord.findMany({
where: {
Expand All @@ -71,6 +74,7 @@ export default class AutorecordModule extends DexareModule<DexareClient<CraigBot
});
autorecords.forEach((autorecord) => this.autorecords.set(autorecord.channelId, autorecord));
this.lastRefresh = Date.now();
this.fetching = false;
}

async upsert(data: AutoRecordUpsert) {
Expand Down

0 comments on commit 4bc5b4c

Please sign in to comment.