Skip to content

Commit f5ad9bc

Browse files
committed
only one member at a time
1 parent f800aac commit f5ad9bc

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/webpage/localuser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
} from "./utils/storage/userPreferences";
4545
import {getDeveloperSettings, setDeveloperSettings} from "./utils/storage/devSettings";
4646
import {getLocalSettings, ServiceWorkerModeValues} from "./utils/storage/localSettings.js";
47+
import {PromiseLock} from "./utils/promiseLock.js";
4748
type traceObj = {
4849
micros: number;
4950
calls?: (string | traceObj)[];
@@ -4477,13 +4478,15 @@ class Localuser {
44774478
this.getMemberMap.set(uid, prom2);
44784479
return prom2;
44794480
}
4481+
memberLock = new PromiseLock();
44804482
async resolvemember(id: string, guildid: string): Promise<memberjson | undefined> {
44814483
if (guildid === "@me") {
44824484
return undefined;
44834485
}
44844486
const guild = this.guildids.get(guildid);
44854487
const borked = true;
44864488
if (!guild || (borked && guild.member_count > 250)) {
4489+
const unlock = await this.memberLock.acquireLock();
44874490
try {
44884491
const req = await fetch(this.info.api + "/guilds/" + guildid + "/members/" + id, {
44894492
headers: this.headers,
@@ -4494,6 +4497,8 @@ class Localuser {
44944497
return await req.json();
44954498
} catch {
44964499
return undefined;
4500+
} finally {
4501+
unlock();
44974502
}
44984503
}
44994504
let guildmap = this.waitingmembers.get(guildid);

src/webpage/utils/promiseLock.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export class PromiseLock {
2+
lastLock = Promise.resolve();
3+
async acquireLock() {
4+
const {promise, resolve: res} = Promise.withResolvers<void>();
5+
const last = this.lastLock;
6+
this.lastLock = promise;
7+
await last;
8+
return res;
9+
}
10+
}

0 commit comments

Comments
 (0)