From ee6e022b2a523cfcd05154b2f88abb50e07104ed Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 1 Jan 2023 11:58:16 +0900 Subject: [PATCH] =?UTF-8?q?enhance(server):=20production=E3=81=98=E3=82=83?= =?UTF-8?q?=E3=81=AA=E3=81=84=E9=99=90=E3=82=8A=E3=83=AC=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=83=AA=E3=83=9F=E3=83=83=E3=83=88=E3=82=92=E7=84=A1=E5=8A=B9?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/server/api/RateLimiterService.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/server/api/RateLimiterService.ts b/packages/backend/src/server/api/RateLimiterService.ts index 94a15f94b..c893b60ba 100644 --- a/packages/backend/src/server/api/RateLimiterService.ts +++ b/packages/backend/src/server/api/RateLimiterService.ts @@ -4,12 +4,13 @@ import Redis from 'ioredis'; import { DI } from '@/di-symbols.js'; import type Logger from '@/logger.js'; import { LoggerService } from '@/core/LoggerService.js'; -import type { IEndpointMeta } from './endpoints.js'; import { bindThis } from '@/decorators.js'; +import type { IEndpointMeta } from './endpoints.js'; @Injectable() export class RateLimiterService { private logger: Logger; + private disabled = false; constructor( @Inject(DI.redis) @@ -18,13 +19,17 @@ export class RateLimiterService { private loggerService: LoggerService, ) { this.logger = this.loggerService.getLogger('limiter'); + + if (process.env.NODE_ENV !== 'production') { + this.disabled = true; + } } @bindThis public limit(limitation: IEndpointMeta['limit'] & { key: NonNullable }, actor: string) { return new Promise((ok, reject) => { - if (process.env.NODE_ENV === 'test') ok(); - + if (this.disabled) ok(); + // Short-term limit const min = (): void => { const minIntervalLimiter = new Limiter({