From 7f18b6eda6e38c41c1490d75ca3c0863456b27d7 Mon Sep 17 00:00:00 2001 From: Cookiezaurs Date: Thu, 9 Mar 2023 16:13:01 +0200 Subject: [PATCH] [bugfix][view] Views were not recorded in cases when in same request there was action with new view name. --- plugins/views/api/api.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/plugins/views/api/api.js b/plugins/views/api/api.js index 1e108f4f20a..50761b13f2e 100644 --- a/plugins/views/api/api.js +++ b/plugins/views/api/api.js @@ -1462,6 +1462,9 @@ const escapedViewSegments = { "name": true, "segment": true, "height": true, "wi options.upsert = false; } common.db.collection(collection).findAndModify(query, {}, update, options, function(err2, view2) { + if (err2) { + log.e(err); + } if (view2 && view2.value) { callback(err, view2.value); common.readBatcher.invalidate(collection, query, {}, false); @@ -1485,6 +1488,9 @@ const escapedViewSegments = { "name": true, "segment": true, "height": true, "wi options.upsert = false; } common.db.collection(collection).findAndModify(query, {}, update, options, function(err, view) { + if (err) { + log.e(err); + } if (view && view.value) { callback(err, view.value); } @@ -1715,8 +1721,10 @@ const escapedViewSegments = { "name": true, "segment": true, "height": true, "wi if (haveVisit) { common.db.collection('app_userviews' + params.app_id).findOneAndUpdate({'_id': params.app_user.uid}, {$max: lastView}, {upsert: true, new: false, projection: projection}, function(err2, view2) { for (let p = 0; p < results.length; p++) { - var currEvent = results[p]; - recordMetrics(params, currEvent, params.app_user, view2 && view2.ok ? view2.value : null, viewInfo); + if (results[p]) { + var currEvent = results[p]; + recordMetrics(params, currEvent, params.app_user, view2 && view2.ok ? view2.value : null, viewInfo); + } } }); } @@ -1726,6 +1734,10 @@ const escapedViewSegments = { "name": true, "segment": true, "height": true, "wi plugins.dispatch("/plugins/drill", {params: params, dbAppUser: params.app_user, events: runDrill}); } + }, function(onfail) { + log.e(JSON.stringify(onfail || "")); + }).catch(function(rejection) { + log.e(rejection); }); resolve(); }); @@ -1803,6 +1815,9 @@ const escapedViewSegments = { "name": true, "segment": true, "height": true, "wi currEvent.viewAlias = escapedMetricVal; resolve(currEvent); } + else { + resolve(false); + } }); } else if (currEvent.segmentation.view) { @@ -1812,6 +1827,9 @@ const escapedViewSegments = { "name": true, "segment": true, "height": true, "wi currEvent.viewAlias = common.db.encode(view._id + ""); resolve(currEvent); } + else { + resolve(false); + } }); } else {