Просмотр исходного кода

Refactoring of RateLimiterFactory

Shun Miyazawa 1 год назад
Родитель
Сommit
4a28490384

+ 3 - 5
apps/app/src/features/rate-limiter/middleware/rate-limiter-factory.ts

@@ -14,11 +14,9 @@ class RateLimiterFactory {
   getOrCreateRateLimiter(endpoint: string, maxRequests: number): RateLimiterMongo {
     const key = this.generateKey(endpoint);
 
-    if (this.rateLimiters.has(key)) {
-      const instance = this.rateLimiters.get(key);
-      if (instance != null) {
-        return instance;
-      }
+    const cachedRateLimiter = this.rateLimiters.get(key);
+    if (cachedRateLimiter != null) {
+      return cachedRateLimiter;
     }
 
     const opts: IRateLimiterMongoOptions = {