update rate limit

This commit is contained in:
pilcrowOnPaper 2024-10-06 22:16:58 +09:00
parent 1435147dcf
commit eadc5b2e6b

View file

@ -34,12 +34,9 @@ export class RefillingTokenBucket<_Key> {
return true; return true;
} }
const refill = Math.floor((now - bucket.refilledAt) / (this.refillIntervalSeconds * 1000)); const refill = Math.floor((now - bucket.refilledAt) / (this.refillIntervalSeconds * 1000));
if (refill > 0) {
bucket.count = Math.min(bucket.count + refill, this.max); bucket.count = Math.min(bucket.count + refill, this.max);
bucket.refilledAt = now; bucket.refilledAt = now;
}
if (bucket.count < cost) { if (bucket.count < cost) {
this.storage.set(key, bucket);
return false; return false;
} }
bucket.count -= cost; bucket.count -= cost;
@ -121,7 +118,6 @@ export class ExpiringTokenBucket<_Key> {
bucket.count = this.max; bucket.count = this.max;
} }
if (bucket.count < cost) { if (bucket.count < cost) {
this.storage.set(key, bucket);
return false; return false;
} }
bucket.count -= cost; bucket.count -= cost;