From 1b5bedc1d0330f0d639dafefeea41d86f95db914 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 19 Aug 2024 19:13:37 +0100 Subject: [PATCH] thunk the min/max promises this prevents generating promises we don't use, which would get logged by the node vm and spam the logs --- .../backend/src/server/api/RateLimiterService.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/server/api/RateLimiterService.ts b/packages/backend/src/server/api/RateLimiterService.ts index 52d73baa0a..a30cb2d47d 100644 --- a/packages/backend/src/server/api/RateLimiterService.ts +++ b/packages/backend/src/server/api/RateLimiterService.ts @@ -38,7 +38,7 @@ export class RateLimiterService { } // Short-term limit - const min = new Promise((ok, reject) => { + const minP = () => { return new Promise((ok, reject) => { const minIntervalLimiter = new Limiter({ id: `${actor}:${limitation.key}:min`, duration: limitation.minInterval! * factor, @@ -57,16 +57,16 @@ export class RateLimiterService { return reject({ code: 'BRIEF_REQUEST_INTERVAL', info }); } else { if (hasLongTermLimit) { - return max.then(ok, reject); + return maxP().then(ok, reject); } else { return ok(); } } }); - }); + }) }; // Long term limit - const max = new Promise((ok, reject) => { + const maxP = () => { return new Promise((ok, reject) => { const limiter = new Limiter({ id: `${actor}:${limitation.key}`, duration: limitation.duration! * factor, @@ -87,7 +87,7 @@ export class RateLimiterService { return ok(); } }); - }); + }) }; const hasShortTermLimit = typeof limitation.minInterval === 'number'; @@ -96,9 +96,9 @@ export class RateLimiterService { typeof limitation.max === 'number'; if (hasShortTermLimit) { - return min; + return minP(); } else if (hasLongTermLimit) { - return max; + return maxP(); } else { return Promise.resolve(); }