@@ -82,9 +82,7 @@ export default class GrouperWorker extends Worker {
82
82
/**
83
83
* Find event by group hash.
84
84
*/
85
- let existedEvent = await this . getEvent ( task . projectId , {
86
- groupHash : uniqueEventHash ,
87
- } ) ;
85
+ let existedEvent = await this . getEvent ( task . projectId , uniqueEventHash ) ;
88
86
89
87
/**
90
88
* If we couldn't group by group hash (title), try grouping by Levenshtein distance with last N events
@@ -131,6 +129,13 @@ export default class GrouperWorker extends Worker {
131
129
usersAffected : incrementAffectedUsers ? 1 : 0 ,
132
130
} as GroupedEventDBScheme ) ;
133
131
132
+ const eventCacheKey = await this . getEventCacheKey ( task . projectId , uniqueEventHash ) ;
133
+
134
+ /**
135
+ * If event is saved, then cached event state is no longer actual, so we should remove it
136
+ */
137
+ this . cache . del ( eventCacheKey ) ;
138
+
134
139
/**
135
140
* Increment daily affected users for the first event
136
141
*/
@@ -372,25 +377,37 @@ export default class GrouperWorker extends Worker {
372
377
* Returns finds event by query from project with passed ID
373
378
*
374
379
* @param projectId - project's identifier
375
- * @param query - mongo query string
380
+ * @param groupHash - group hash of the event
376
381
*/
377
- private async getEvent ( projectId : string , query : Record < string , unknown > ) : Promise < GroupedEventDBScheme > {
382
+ private async getEvent ( projectId : string , groupHash : string ) : Promise < GroupedEventDBScheme > {
378
383
if ( ! mongodb . ObjectID . isValid ( projectId ) ) {
379
384
throw new ValidationError ( 'Controller.saveEvent: Project ID is invalid or missed' ) ;
380
385
}
381
386
382
- const eventCacheKey = ` ${ projectId } : ${ JSON . stringify ( query ) } ` ;
387
+ const eventCacheKey = await this . getEventCacheKey ( projectId , groupHash ) ;
383
388
384
389
return this . cache . get ( eventCacheKey , async ( ) => {
385
390
return this . db . getConnection ( )
386
391
. collection ( `events:${ projectId } ` )
387
- . findOne ( query )
392
+ . findOne ( {
393
+ groupHash,
394
+ } )
388
395
. catch ( ( err ) => {
389
396
throw new DatabaseReadWriteError ( err ) ;
390
397
} ) ;
391
398
} ) ;
392
399
}
393
400
401
+ /**
402
+ * Method that returns event cache key based on projectId and groupHash
403
+ * @param projectId - used for cache key creation
404
+ * @param groupHash - used for cache key creation
405
+ * @returns cache key
406
+ */
407
+ private async getEventCacheKey ( projectId : string , groupHash : string ) : Promise < string > {
408
+ return `${ projectId } :${ JSON . stringify ( { groupHash : groupHash } ) } `
409
+ }
410
+
394
411
/**
395
412
* Save event to database
396
413
*
0 commit comments