Skip to content

Commit 4739d48

Browse files
authored
fix(memory-storage): don't increment handledRequestCount when updating a handled request (#3827)
Increments the `handledRequestCount` counter only on the initial request `handledAt` / `orderNo` change. Subsequent `handledAt` changes do not increment the counter. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
1 parent f04f62f commit 4739d48

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

packages/memory-storage/src/resource-clients/request-queue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ export class RequestQueueClient extends BaseClient implements storage.RequestQue
551551
existingQueueById.pendingRequestCount += requestWasHandledBeforeUpdate ? 1 : -1;
552552
}
553553

554-
if (requestIsHandledAfterUpdate) {
554+
if (isRequestHandledStateChanging && requestIsHandledAfterUpdate) {
555555
existingQueueById.handledRequestCount += 1;
556556
}
557557

packages/memory-storage/test/request-queue/handledRequestCount-should-update.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,24 @@ describe('RequestQueue handledRequestCount should update', () => {
5050
const updatedStatistics = await requestQueue.get();
5151
expect(updatedStatistics?.handledRequestCount).toEqual(2);
5252
});
53+
54+
test('updating an already handled request should not increment the handledRequestCount again', async () => {
55+
const { requestId } = await requestQueue.addRequest({
56+
url: 'http://example.com/4',
57+
uniqueKey: '4',
58+
handledAt: new Date().toISOString(),
59+
});
60+
61+
const { handledRequestCount } = (await requestQueue.get())!;
62+
63+
await requestQueue.updateRequest({
64+
url: 'http://example.com/4',
65+
uniqueKey: '4',
66+
id: requestId,
67+
handledAt: new Date().toISOString(),
68+
});
69+
70+
const updatedStatistics = await requestQueue.get();
71+
expect(updatedStatistics?.handledRequestCount).toEqual(handledRequestCount);
72+
});
5373
});

0 commit comments

Comments
 (0)