@@ -401,12 +401,18 @@ var processToDrill = async function(params, drill_updates, callback) {
401
401
"ts" : events [ i ] . timestamp || Date . now ( ) . valueOf ( ) ,
402
402
"uid" : params . app_user . uid ,
403
403
"_uid" : params . app_user . _id ,
404
- "did" : params . app_user . did ,
405
- "ce" : true ,
404
+ "did" : params . app_user . did
406
405
//d, w,m,h
407
406
} ;
408
407
if ( currEvent . key . indexOf ( '[CLY]_' ) === 0 ) {
409
- dbEventObject . ce = false ;
408
+ dbEventObject . n = events [ i ] . key ;
409
+ }
410
+ else {
411
+ dbEventObject . n = events [ i ] . key ;
412
+ dbEventObject . e = "[CLY]_custom" ;
413
+ }
414
+ if ( currEvent . name ) {
415
+ dbEventObject . n = currEvent . name ;
410
416
}
411
417
412
418
if ( dbAppUser && dbAppUser [ common . dbUserMap . user_id ] ) {
@@ -557,7 +563,7 @@ var processToDrill = async function(params, drill_updates, callback) {
557
563
eventsToInsert . push ( { "insertOne" : { "document" : dbEventObject } } ) ;
558
564
if ( eventKey === "[CLY]_view" ) {
559
565
var view_id = crypto . createHash ( 'md5' ) . update ( currEvent . segmentation . name ) . digest ( 'hex' ) ;
560
- viewUpdate [ view_id ] = { "lvid" : dbEventObject . _id , "ts" : dbEventObject . ts } ;
566
+ viewUpdate [ view_id ] = { "lvid" : dbEventObject . _id , "ts" : dbEventObject . ts , "a" : params . app_id + "" } ;
561
567
if ( currEvent . segmentation ) {
562
568
var sgm = { } ;
563
569
var have_sgm = false ;
@@ -580,25 +586,26 @@ var processToDrill = async function(params, drill_updates, callback) {
580
586
for ( var z4 = 0 ; z4 < drill_updates . length ; z4 ++ ) {
581
587
eventsToInsert . push ( drill_updates [ z4 ] ) ;
582
588
}
583
-
584
589
}
585
590
if ( eventsToInsert . length > 0 ) {
586
591
try {
587
592
await common . drillDb . collection ( "drill_events" ) . bulkWrite ( eventsToInsert , { ordered : false } ) ;
593
+ callback ( null ) ;
588
594
if ( Object . keys ( viewUpdate ) . length ) {
589
595
//updates app_viewdata colelction.If delayed new incoming view updates will not have reference. (So can do in aggregator only if we can insure minimal delay)
590
596
try {
591
- await common . db . collection ( "app_userviews" + params . app_id ) . updateOne ( { _id : params . app_user . uid } , { $set : viewUpdate } , { upsert : true } ) ;
597
+ await common . db . collection ( "app_userviews" ) . updateOne ( { _id : params . app_id + "_" + params . app_user . uid } , { $set : viewUpdate } , { upsert : true } ) ;
592
598
}
593
599
catch ( err ) {
594
600
log . e ( err ) ;
595
601
}
596
602
}
597
- callback ( null ) ;
603
+
598
604
}
599
605
catch ( errors ) {
600
606
var realError ;
601
607
if ( errors && Array . isArray ( errors ) ) {
608
+ log . e ( JSON . stringify ( errors ) ) ;
602
609
for ( let i = 0 ; i < errors . length ; i ++ ) {
603
610
if ( [ 11000 , 10334 , 17419 ] . indexOf ( errors [ i ] . code ) === - 1 ) {
604
611
realError = true ;
@@ -609,16 +616,17 @@ var processToDrill = async function(params, drill_updates, callback) {
609
616
callback ( realError ) ;
610
617
}
611
618
else {
619
+ callback ( null ) ;
612
620
if ( Object . keys ( viewUpdate ) . length ) {
613
621
//updates app_viewdata colelction.If delayed new incoming view updates will not have reference. (So can do in aggregator only if we can insure minimal delay)
614
622
try {
615
- await common . db . collection ( "app_userviews" + params . app_id ) . updateOne ( { _id : params . app_user . uid } , { $set : viewUpdate } , { upsert : true } ) ;
623
+ await common . db . collection ( "app_userviews" ) . updateOne ( { _id : params . app_id + "_" + params . app_user . uid } , { $set : viewUpdate } , { upsert : true } ) ;
616
624
}
617
625
catch ( err ) {
618
626
log . e ( err ) ;
619
627
}
620
628
}
621
- callback ( null ) ;
629
+
622
630
}
623
631
}
624
632
else {
@@ -701,7 +709,14 @@ const processRequestData = (ob, done) => {
701
709
update = common . mergeQuery ( update , ob . updates [ i ] ) ;
702
710
}
703
711
}
704
- Promise . all ( [ common . updateAppUser ( ob . params , update , false , true ) ] ) . then ( function ( ) {
712
+ //var SaveAppUser = Date.now().valueOf();
713
+
714
+ common . updateAppUser ( ob . params , update , false , function ( ) {
715
+
716
+ /*var AfterSaveAppUser = Date.now().valueOf();
717
+ if (AfterSaveAppUser - SaveAppUser > treshold) {
718
+ console.log("SaveAppUser time: " + (AfterSaveAppUser - SaveAppUser));
719
+ }*/
705
720
processToDrill ( ob . params , ob . drill_updates , function ( error ) {
706
721
if ( error ) {
707
722
common . returnMessage ( ob . params , 400 , 'Could not record events:' + error ) ;
@@ -712,10 +727,6 @@ const processRequestData = (ob, done) => {
712
727
}
713
728
} ) ;
714
729
715
- } ) . catch ( function ( err ) {
716
- log . e ( err ) ;
717
- common . returnMessage ( ob . params , 400 , 'Cannot process request' ) ;
718
- done ( ) ;
719
730
} ) ;
720
731
} ;
721
732
@@ -730,7 +741,6 @@ plugins.register("/sdk/process_request", async function(ob) {
730
741
*
731
742
* @param {* } params - request parameters
732
743
* @param {* } done - callback function
733
- * @returns {boolean } - returns false if request is cancelled
734
744
*
735
745
*
736
746
* 1)Get App collection settings
0 commit comments