Skip to content

Commit f5307d6

Browse files
committed
Add REPETITION_CACHE_TTL and dedupe regexpCache
Introduce REPETITION_CACHE_TTL (300s) and replace magic timeout literals with this constant for repetition cache lookups. Move the regexpCache Map declaration to the class top-level to avoid a duplicate declaration and add JSDoc comments for both the TTL and regexp cache to clarify intent and improve maintainability.
1 parent e41b15a commit f5307d6

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

workers/grouper/src/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ const DB_DUPLICATE_KEY_ERROR = '11000';
5353
*/
5454
const MAX_CODE_LINE_LENGTH = 140;
5555

56+
/**
57+
* TTL for repetition cache lookups in seconds
58+
*/
59+
const REPETITION_CACHE_TTL = 300;
60+
5661
/**
5762
* Worker for handling Javascript events
5863
*/
@@ -87,6 +92,11 @@ export default class GrouperWorker extends Worker {
8792
*/
8893
private cacheCleanupInterval: NodeJS.Timeout | null = null;
8994

95+
/**
96+
* Cache for compiled RegExp patterns to avoid repeated compilation
97+
*/
98+
private regexpCache = new Map<string, RegExp>();
99+
90100
/**
91101
* Start consuming messages
92102
*/
@@ -429,11 +439,6 @@ export default class GrouperWorker extends Worker {
429439
return undefined;
430440
}
431441

432-
/**
433-
* Cache for compiled RegExp patterns to avoid repeated compilation
434-
*/
435-
private regexpCache = new Map<string, RegExp>();
436-
437442
/**
438443
* Method that returns matched pattern for event, if event do not match any of patterns return null
439444
*
@@ -525,7 +530,7 @@ export default class GrouperWorker extends Worker {
525530
},
526531
{ projection: { _id: 1 } }
527532
);
528-
}, 300);
533+
}, REPETITION_CACHE_TTL);
529534

530535
if (repetition) {
531536
shouldIncrementRepetitionAffectedUsers = false;
@@ -566,7 +571,7 @@ export default class GrouperWorker extends Worker {
566571
},
567572
{ projection: { _id: 1 } }
568573
);
569-
}, 300);
574+
}, REPETITION_CACHE_TTL);
570575

571576
/**
572577
* If daily repetition exists, don't increment daily affected users

0 commit comments

Comments
 (0)