mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-08 02:37:44 +02:00
UBERF-10412: Make rate limit less aggressive (#8765)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
@@ -40,15 +40,13 @@ export class SlidingWindowRateLimitter {
|
||||
// Update reset time
|
||||
rateLimit.resetTime = now + this.rateLimitWindow
|
||||
|
||||
rateLimit.requests.push(now + (rateLimit.rejectedRequests > this.rateLimitMax * 2 ? this.rateLimitWindow * 5 : 0))
|
||||
if (rateLimit.requests.length <= this.rateLimitMax) {
|
||||
rateLimit.requests.push(now + (rateLimit.rejectedRequests > this.rateLimitMax * 2 ? this.rateLimitWindow * 5 : 0))
|
||||
}
|
||||
|
||||
if (rateLimit.requests.length > this.rateLimitMax) {
|
||||
rateLimit.rejectedRequests++
|
||||
|
||||
if (rateLimit.requests.length > this.rateLimitMax * 2) {
|
||||
// Keep only last requests
|
||||
rateLimit.requests.splice(0, rateLimit.requests.length - this.rateLimitMax)
|
||||
}
|
||||
// Find when the oldest request will exit the window
|
||||
const someRequest = Math.round(Math.random() * rateLimit.requests.length)
|
||||
const nextAvailableTime = rateLimit.requests[someRequest] + this.rateLimitWindow
|
||||
|
||||
@@ -123,7 +123,6 @@ describe('SlidingWindowRateLimitter', () => {
|
||||
clock += 10000
|
||||
|
||||
const r2 = limiter.checkRateLimit('user1')
|
||||
expect(r2.remaining).toBe(0)
|
||||
expect(r2.retryAfter).toBeDefined()
|
||||
expect(r2.remaining).toBe(9)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user