@@ -412,10 +412,17 @@ module.exports = {
412412 { $match : { projectId : project . _id . toString ( ) } } ,
413413 {
414414 $project : {
415- release : { $convert : { input : '$release' , to : 'string' , onError : '' , onNull : '' } } ,
416- commitsCount : { $size : { $ifNull : [ '$commits' , [ ] ] } } ,
417- filesCount : { $size : { $ifNull : [ '$files' , [ ] ] } } ,
418- _releaseIdSec : { $floor : { $divide : [ { $toLong : { $toDate : '$_id' } } , 1000 ] } } ,
415+ release : {
416+ $convert : {
417+ input : '$release' ,
418+ to : 'string' ,
419+ onError : '' ,
420+ onNull : '' ,
421+ } ,
422+ } ,
423+ commitsCount : { $size : { $ifNull : [ '$commits' , [ ] ] } } ,
424+ filesCount : { $size : { $ifNull : [ '$files' , [ ] ] } } ,
425+ _releaseIdSec : { $floor : { $divide : [ { $toLong : { $toDate : '$_id' } } , 1000 ] } } ,
419426 } ,
420427 } ,
421428 { $match : { release : { $ne : '' } } } ,
@@ -424,8 +431,27 @@ module.exports = {
424431 from : 'events:' + project . _id ,
425432 let : { rel : '$release' } ,
426433 pipeline : [
427- { $match : { $expr : { $eq : [ { $convert : { input : '$payload.release' , to : 'string' , onError : '' , onNull : '' } } , '$$rel' ] } } } ,
428- { $group : { _id : null , minTs : { $min : '$timestamp' } , count : { $sum : 1 } } } ,
434+ {
435+ $match : {
436+ $expr : {
437+ $eq : [ {
438+ $convert : {
439+ input : '$payload.release' ,
440+ to : 'string' ,
441+ onError : '' ,
442+ onNull : '' ,
443+ } ,
444+ } , '$$rel' ] ,
445+ } ,
446+ } ,
447+ } ,
448+ {
449+ $group : {
450+ _id : null ,
451+ minTs : { $min : '$timestamp' } ,
452+ count : { $sum : 1 } ,
453+ } ,
454+ } ,
429455 ] ,
430456 as : 'eventAgg' ,
431457 } ,
@@ -436,9 +462,9 @@ module.exports = {
436462 release : 1 ,
437463 commitsCount : 1 ,
438464 filesCount : 1 ,
439- newEventsCount : { $ifNull : [ { $arrayElemAt : [ '$eventAgg.count' , 0 ] } , 0 ] } ,
465+ newEventsCount : { $ifNull : [ { $arrayElemAt : [ '$eventAgg.count' , 0 ] } , 0 ] } ,
440466 timestamp : {
441- $ifNull : [ { $arrayElemAt : [ '$eventAgg.minTs' , 0 ] } , '$_releaseIdSec' ] ,
467+ $ifNull : [ { $arrayElemAt : [ '$eventAgg.minTs' , 0 ] } , '$_releaseIdSec' ] ,
442468 } ,
443469 } ,
444470 } ,
0 commit comments