File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -403,6 +403,17 @@ class EventsFactory extends Factory {
403403 return { 'event.assignee' : String ( assignee ) } ;
404404 } ) ( ) ;
405405
406+ /** When false, $limit can move before the $lookups. */
407+ const hasContentFilters =
408+ escapedSearch . length > 0 ||
409+ Boolean ( release ) ||
410+ Boolean ( assignee ) ||
411+ Object . keys ( matchFilter ) . length > 0 ;
412+
413+ if ( ! hasContentFilters ) {
414+ pipeline . push ( { $limit : limit + 1 } ) ;
415+ }
416+
406417 pipeline . push (
407418 /**
408419 * Left outer join original event on groupHash field
@@ -434,21 +445,25 @@ class EventsFactory extends Factory {
434445 path : '$repetition' ,
435446 preserveNullAndEmptyArrays : true ,
436447 } ,
437- } ,
438- {
439- $match : {
440- ...matchFilter ,
441- ...searchFilter ,
442- ...releaseFilter ,
443- ...assigneeFilter ,
444- } ,
445- } ,
446- { $limit : limit + 1 } ,
447- {
448- $unset : 'groupHash' ,
449448 }
450449 ) ;
451450
451+ if ( hasContentFilters ) {
452+ pipeline . push (
453+ {
454+ $match : {
455+ ...matchFilter ,
456+ ...searchFilter ,
457+ ...releaseFilter ,
458+ ...assigneeFilter ,
459+ } ,
460+ } ,
461+ { $limit : limit + 1 }
462+ ) ;
463+ }
464+
465+ pipeline . push ( { $unset : 'groupHash' } ) ;
466+
452467 const cursor = this . getCollection ( this . TYPES . DAILY_EVENTS ) . aggregate ( pipeline ) ;
453468 const result = await cursor . toArray ( ) ;
454469
You can’t perform that action at this time.
0 commit comments