From 00884590b549e67333ec06b570cd3b4cdb5fdf6d Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 15 Aug 2024 22:50:11 +0200 Subject: [PATCH] FiatApi: improve setting reported usages on rate limit Set usages with mode increase-only, for highest usages to eventually survive, in case of responses of parallel requests arriving out of order, and to avoid removing counts of additional requests sent in the meantime. --- src/fiat-api/FiatApi.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fiat-api/FiatApi.ts b/src/fiat-api/FiatApi.ts index 50f1b4e..975671b 100644 --- a/src/fiat-api/FiatApi.ts +++ b/src/fiat-api/FiatApi.ts @@ -887,7 +887,10 @@ async function _fetch( && typeof parsedResponse.RateLimit?.max_calls?.[timePeriod] === 'number', )) { const { calls_made: usages, max_calls: limits } = parsedResponse.RateLimit; - rateLimitScheduler.setUsages(usages); + // Set usages with mode increase-only, for highest usages to eventually survive, in case of responses of + // parallel requests arriving out of order, and to avoid removing counts of additional requests sent in + // the meantime. + rateLimitScheduler.setUsages(usages, 'increase-only'); // Ignore daily and monthly limits in hopes of the usage being reset earlier than on day or month reset, // for example by IP change, but limit parallel requests when the daily or monthly limit is hit to avoid // unnecessary parallel requests, see above. The parallel limit is reset on the next successful request.