@@ -388,10 +388,17 @@ module.exports = {
388388 { $match : { projectId : project . _id . toString ( ) } } ,
389389 {
390390 $project : {
391- release : { $convert : { input : '$release' , to : 'string' , onError : '' , onNull : '' } } ,
392- commitsCount : { $size : { $ifNull : [ '$commits' , [ ] ] } } ,
393- filesCount : { $size : { $ifNull : [ '$files' , [ ] ] } } ,
394- _releaseIdSec : { $floor : { $divide : [ { $toLong : { $toDate : '$_id' } } , 1000 ] } } ,
391+ release : {
392+ $convert : {
393+ input : '$release' ,
394+ to : 'string' ,
395+ onError : '' ,
396+ onNull : '' ,
397+ } ,
398+ } ,
399+ commitsCount : { $size : { $ifNull : [ '$commits' , [ ] ] } } ,
400+ filesCount : { $size : { $ifNull : [ '$files' , [ ] ] } } ,
401+ _releaseIdSec : { $floor : { $divide : [ { $toLong : { $toDate : '$_id' } } , 1000 ] } } ,
395402 } ,
396403 } ,
397404 { $match : { release : { $ne : '' } } } ,
@@ -400,8 +407,27 @@ module.exports = {
400407 from : 'events:' + project . _id ,
401408 let : { rel : '$release' } ,
402409 pipeline : [
403- { $match : { $expr : { $eq : [ { $convert : { input : '$payload.release' , to : 'string' , onError : '' , onNull : '' } } , '$$rel' ] } } } ,
404- { $group : { _id : null , minTs : { $min : '$timestamp' } , count : { $sum : 1 } } } ,
410+ {
411+ $match : {
412+ $expr : {
413+ $eq : [ {
414+ $convert : {
415+ input : '$payload.release' ,
416+ to : 'string' ,
417+ onError : '' ,
418+ onNull : '' ,
419+ } ,
420+ } , '$$rel' ] ,
421+ } ,
422+ } ,
423+ } ,
424+ {
425+ $group : {
426+ _id : null ,
427+ minTs : { $min : '$timestamp' } ,
428+ count : { $sum : 1 } ,
429+ } ,
430+ } ,
405431 ] ,
406432 as : 'eventAgg' ,
407433 } ,
@@ -412,9 +438,9 @@ module.exports = {
412438 release : 1 ,
413439 commitsCount : 1 ,
414440 filesCount : 1 ,
415- newEventsCount : { $ifNull : [ { $arrayElemAt : [ '$eventAgg.count' , 0 ] } , 0 ] } ,
441+ newEventsCount : { $ifNull : [ { $arrayElemAt : [ '$eventAgg.count' , 0 ] } , 0 ] } ,
416442 timestamp : {
417- $ifNull : [ { $arrayElemAt : [ '$eventAgg.minTs' , 0 ] } , '$_releaseIdSec' ] ,
443+ $ifNull : [ { $arrayElemAt : [ '$eventAgg.minTs' , 0 ] } , '$_releaseIdSec' ] ,
418444 } ,
419445 } ,
420446 } ,
0 commit comments