Skip to content

Commit 4955ea4

Browse files
committed
imp(grouper): cache getProjectPatterns response
1 parent 039ce1f commit 4955ea4

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

workers/grouper/src/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,20 @@ export default class GrouperWorker extends Worker {
313313
* @returns EventPatterns object with projectId and list of patterns
314314
*/
315315
private async getProjectPatterns(projectId: string): Promise<string[]> {
316-
const project = await this.accountsDb.getConnection()
317-
.collection('projects')
318-
.findOne({
319-
_id: new mongodb.ObjectId(projectId),
320-
});
316+
return this.cache.get(`project:${projectId}:patterns`, async () => {
317+
const project = await this.accountsDb.getConnection()
318+
.collection('projects')
319+
.findOne({
320+
_id: new mongodb.ObjectId(projectId),
321+
});
321322

322-
return project.eventGroupingPatterns;
323+
return project?.eventGroupingPatterns || [];
324+
},
325+
/**
326+
* Cache project patterns for 5 minutes since they don't change frequently
327+
*/
328+
/* eslint-disable-next-line @typescript-eslint/no-magic-numbers */
329+
5 * TimeMs.MINUTE / MS_IN_SEC);
323330
}
324331

325332
/**

0 commit comments

Comments
 (0)