Skip to content

Commit 418256c

Browse files
committed
Use concurrency to improve performance
1 parent ed17066 commit 418256c

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

lambdas/api-handler/src/services/letter-operations.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,20 @@ export const getPendingLetters = async (
5151
letterQueueRepo: LetterQueueRepository,
5252
visibilityTimeout: number,
5353
): Promise<LetterBase[]> => {
54+
const CONCURRENCY = 5;
55+
5456
const pendingLetters = await letterQueueRepo.getLetters(supplierId, limit);
5557
const timestamp = new Date(Date.now() + visibilityTimeout * 1000);
56-
for (const letter of pendingLetters) {
57-
await letterQueueRepo.updateLetterTimestamp(letter, timestamp);
58+
59+
for (let i = 0; i < pendingLetters.length; i += CONCURRENCY) {
60+
const window = pendingLetters.slice(i, i + CONCURRENCY);
61+
await Promise.all(
62+
window.map((letter) =>
63+
letterQueueRepo.updateLetterTimestamp(letter, timestamp),
64+
),
65+
);
5866
}
67+
5968
return pendingLetters.map((letter) => mapPendingLetterToLetterBase(letter));
6069
};
6170

0 commit comments

Comments
 (0)