Skip to content

Commit e55e2fe

Browse files
committed
changed hard coded numbers to to the proper variables
1 parent 6fcefc3 commit e55e2fe

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/rateLimiters/tokenBucket.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class TokenBucket implements RateLimiter {
5353
if (bucketJSON === null) {
5454
const newUserBucket: RedisBucket = {
5555
// conditionally set tokens depending on how many are requested comapred to the capacity
56-
tokens: tokens > this.capacity ? 10 : this.capacity - tokens,
56+
tokens: tokens > this.capacity ? this.capacity : this.capacity - tokens,
5757
timestamp,
5858
};
5959
// reject the request, not enough tokens could even be in the bucket
@@ -98,11 +98,11 @@ class TokenBucket implements RateLimiter {
9898
timestamp: number
9999
): number => {
100100
const timeSinceLastQueryInSeconds: number = Math.floor(
101-
(timestamp - bucket.timestamp) / 1000
101+
(timestamp - bucket.timestamp) / 1000 // 1000 ms in a second
102102
);
103103
const tokensToAdd = timeSinceLastQueryInSeconds * this.refillRate;
104104
const updatedTokenCount = bucket.tokens + tokensToAdd;
105-
return updatedTokenCount > this.capacity ? 10 : updatedTokenCount;
105+
return updatedTokenCount > this.capacity ? this.capacity : updatedTokenCount;
106106
};
107107
}
108108

0 commit comments

Comments
 (0)