From eadc5b2e6b713a76ab8bdfabfea2e096fd5058a9 Mon Sep 17 00:00:00 2001 From: pilcrowOnPaper Date: Sun, 6 Oct 2024 22:16:58 +0900 Subject: [PATCH] update rate limit --- src/lib/server/rate-limit.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/lib/server/rate-limit.ts b/src/lib/server/rate-limit.ts index f7bae8b..7517e26 100644 --- a/src/lib/server/rate-limit.ts +++ b/src/lib/server/rate-limit.ts @@ -34,12 +34,9 @@ export class RefillingTokenBucket<_Key> { return true; } const refill = Math.floor((now - bucket.refilledAt) / (this.refillIntervalSeconds * 1000)); - if (refill > 0) { - bucket.count = Math.min(bucket.count + refill, this.max); - bucket.refilledAt = now; - } + bucket.count = Math.min(bucket.count + refill, this.max); + bucket.refilledAt = now; if (bucket.count < cost) { - this.storage.set(key, bucket); return false; } bucket.count -= cost; @@ -121,7 +118,6 @@ export class ExpiringTokenBucket<_Key> { bucket.count = this.max; } if (bucket.count < cost) { - this.storage.set(key, bucket); return false; } bucket.count -= cost;