Skip to content

Commit e5ea73e

Browse files
committed
refactor(paymaster): pass batch into flush and clear it explicitly
1 parent a8cd9f3 commit e5ea73e

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

workers/paymaster/src/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,12 @@ export default class PaymasterWorker extends Worker {
232232

233233
let batch: WorkspaceDBScheme[] = [];
234234

235-
const flush = async (): Promise<void> => {
236-
if (batch.length === 0) {
235+
const flush = async (currentBatch: WorkspaceDBScheme[]): Promise<void> => {
236+
if (currentBatch.length === 0) {
237237
return;
238238
}
239239

240-
const current = batch;
241-
242-
batch = [];
243-
await Promise.all(current.map((workspace) => this.processWorkspaceSubscriptionCheck(workspace)));
240+
await Promise.all(currentBatch.map((workspace) => this.processWorkspaceSubscriptionCheck(workspace)));
244241
};
245242

246243
try {
@@ -258,11 +255,12 @@ export default class PaymasterWorker extends Worker {
258255
batch.push(workspace);
259256

260257
if (batch.length >= WORKSPACE_PROCESSING_CONCURRENCY) {
261-
await flush();
258+
await flush(batch);
259+
batch = [];
262260
}
263261
}
264262

265-
await flush();
263+
await flush(batch);
266264
} finally {
267265
await cursor.close();
268266
}

0 commit comments

Comments
 (0)