Skip to content

Commit 9dc71a7

Browse files
committed
Add optimization
1 parent 3ab7e5c commit 9dc71a7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/ratelimiting/RateLimiter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ export class RateLimiter {
2222
(timestamp) => currentTime - timestamp <= windowSizeInMS
2323
);
2424

25+
// Ensure the number of entries exceeds maxRequests by only 1
26+
if (filteredTimestamps.length > maxRequests + 1) {
27+
filteredTimestamps.splice(
28+
0,
29+
filteredTimestamps.length - (maxRequests + 1)
30+
);
31+
}
32+
2533
// Add current request timestamp to the list
2634
filteredTimestamps.push(currentTime);
2735

0 commit comments

Comments
 (0)