File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " hawk.api" ,
3- "version" : " 1.5.2 " ,
3+ "version" : " 1.5.3 " ,
44 "main" : " index.ts" ,
55 "license" : " BUSL-1.1" ,
66 "scripts" : {
Original file line number Diff line number Diff line change @@ -403,6 +403,22 @@ class EventsFactory extends Factory {
403403 return { 'event.assignee' : String ( assignee ) } ;
404404 } ) ( ) ;
405405
406+ /**
407+ * These filters match joined event.* fields, so their $match must run
408+ * after the lookups. With none set, $limit can move before the lookups
409+ * and skip joining rows we'd drop anyway (~8.8s).
410+ * Trim search to match searchFilter's own condition.
411+ */
412+ const hasContentFilters =
413+ search . trim ( ) . length > 0 ||
414+ Boolean ( release ) ||
415+ Boolean ( assignee ) ||
416+ Object . keys ( matchFilter ) . length > 0 ;
417+
418+ if ( ! hasContentFilters ) {
419+ pipeline . push ( { $limit : limit + 1 } ) ;
420+ }
421+
406422 pipeline . push (
407423 /**
408424 * Left outer join original event on groupHash field
@@ -434,21 +450,25 @@ class EventsFactory extends Factory {
434450 path : '$repetition' ,
435451 preserveNullAndEmptyArrays : true ,
436452 } ,
437- } ,
438- {
439- $match : {
440- ...matchFilter ,
441- ...searchFilter ,
442- ...releaseFilter ,
443- ...assigneeFilter ,
444- } ,
445- } ,
446- { $limit : limit + 1 } ,
447- {
448- $unset : 'groupHash' ,
449453 }
450454 ) ;
451455
456+ if ( hasContentFilters ) {
457+ pipeline . push (
458+ {
459+ $match : {
460+ ...matchFilter ,
461+ ...searchFilter ,
462+ ...releaseFilter ,
463+ ...assigneeFilter ,
464+ } ,
465+ } ,
466+ { $limit : limit + 1 }
467+ ) ;
468+ }
469+
470+ pipeline . push ( { $unset : 'groupHash' } ) ;
471+
452472 const cursor = this . getCollection ( this . TYPES . DAILY_EVENTS ) . aggregate ( pipeline ) ;
453473 const result = await cursor . toArray ( ) ;
454474
You can’t perform that action at this time.
0 commit comments