Skip to content

Commit 6cfff05

Browse files
author
Cookiezaurs
committed
linting
1 parent f47982f commit 6cfff05

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

api/ingestor/requestProcessor.js

+25-11
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,18 @@ var processToDrill = async function(params, drill_updates, callback) {
401401
"ts": events[i].timestamp || Date.now().valueOf(),
402402
"uid": params.app_user.uid,
403403
"_uid": params.app_user._id,
404-
"did": params.app_user.did,
405-
"ce": true,
404+
"did": params.app_user.did
406405
//d, w,m,h
407406
};
408407
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;
410416
}
411417

412418
if (dbAppUser && dbAppUser[common.dbUserMap.user_id]) {
@@ -557,7 +563,7 @@ var processToDrill = async function(params, drill_updates, callback) {
557563
eventsToInsert.push({"insertOne": {"document": dbEventObject}});
558564
if (eventKey === "[CLY]_view") {
559565
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 + ""};
561567
if (currEvent.segmentation) {
562568
var sgm = {};
563569
var have_sgm = false;
@@ -580,25 +586,26 @@ var processToDrill = async function(params, drill_updates, callback) {
580586
for (var z4 = 0; z4 < drill_updates.length;z4++) {
581587
eventsToInsert.push(drill_updates[z4]);
582588
}
583-
584589
}
585590
if (eventsToInsert.length > 0) {
586591
try {
587592
await common.drillDb.collection("drill_events").bulkWrite(eventsToInsert, {ordered: false});
593+
callback(null);
588594
if (Object.keys(viewUpdate).length) {
589595
//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)
590596
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});
592598
}
593599
catch (err) {
594600
log.e(err);
595601
}
596602
}
597-
callback(null);
603+
598604
}
599605
catch (errors) {
600606
var realError;
601607
if (errors && Array.isArray(errors)) {
608+
log.e(JSON.stringify(errors));
602609
for (let i = 0; i < errors.length; i++) {
603610
if ([11000, 10334, 17419].indexOf(errors[i].code) === -1) {
604611
realError = true;
@@ -609,16 +616,17 @@ var processToDrill = async function(params, drill_updates, callback) {
609616
callback(realError);
610617
}
611618
else {
619+
callback(null);
612620
if (Object.keys(viewUpdate).length) {
613621
//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)
614622
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});
616624
}
617625
catch (err) {
618626
log.e(err);
619627
}
620628
}
621-
callback(null);
629+
622630
}
623631
}
624632
else {
@@ -701,7 +709,14 @@ const processRequestData = (ob, done) => {
701709
update = common.mergeQuery(update, ob.updates[i]);
702710
}
703711
}
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(err, userdoc) {
715+
716+
/*var AfterSaveAppUser = Date.now().valueOf();
717+
if (AfterSaveAppUser - SaveAppUser > treshold) {
718+
console.log("SaveAppUser time: " + (AfterSaveAppUser - SaveAppUser));
719+
}*/
705720
processToDrill(ob.params, ob.drill_updates, function(error) {
706721
if (error) {
707722
common.returnMessage(ob.params, 400, 'Could not record events:' + error);
@@ -730,7 +745,6 @@ plugins.register("/sdk/process_request", async function(ob) {
730745
*
731746
* @param {*} params - request parameters
732747
* @param {*} done - callback function
733-
* @returns {boolean} - returns false if request is cancelled
734748
*
735749
*
736750
* 1)Get App collection settings

api/parts/data/cacher.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Cacher {
88
/**
99
* Create batcher instance
1010
* @param {Db} db - database object
11+
* @param {object} options - options object
1112
*/
1213
constructor(db, options) {
1314
this.db = db;

plugins/sources/api/aggregator.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var exported = {},
2-
common = require('../../../api/utils/common.js'),
32
plugins = require('../../pluginManager.js');
43

54
(function() {

test/unit-tests/db.tests.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,17 @@ describe('Testing Simple database operations', function() {
257257

258258
describe("test insert Many(+behaviour on duplicate)", function() {
259259
it("Insert once and check result(promise)", async function(done) {
260-
var rr = await db.collection("testCommands3").insertMany([{"_id": 1, "_id": 2, "_id": 3}]);
260+
var rr = await db.collection("testCommands3").insertMany([{"_id": 1},{ "_id": 2},{"_id": 3}]);
261261

262262
var cursor = db.collection("testCommands3").find();
263263
var res = await cursor.toArray();
264264
res.should.have.property.length(3);
265265
});
266266

267267
it("Insert again and check result(callback)", async function(done) {
268-
var rr = await db.collection("testCommands3").insertMany([{"_id": 4, "_id": 5, "_id": 6}]);
268+
var rr = await db.collection("testCommands3").insertMany([{"_id": 4},{ "_id": 5},{ "_id": 6}]);
269269

270-
db.collection("testCommands3").insertMany([{"_id": 4, "_id": 5, "_id": 6}], function(err, res) {
270+
db.collection("testCommands3").insertMany([{"_id": 4},{ "_id": 5},{ "_id": 6}], function(err, res) {
271271
db.collection("testCommands3").find().toArray(function(err, res) {
272272
res.should.have.property.length(6);
273273
});

0 commit comments

Comments
 (0)