Skip to content

Commit

Permalink
[core] Correct aggregated collection cleanup on event omitting+tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cookiezaurs committed Nov 21, 2024
1 parent 2313d02 commit 1309cae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 2 additions & 3 deletions api/utils/requestProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ const processRequest = (params) => {
return new Promise(function(resolve) {
var collectionNameWoPrefix = common.crypto.createHash('sha1').update(obj.key + params.qstring.app_id).digest('hex');
//removes all document for current segment
common.db.collection("events" + collectionNameWoPrefix).remove({"s": {$in: obj.list}}, {multi: true}, function(err3) {
common.db.collection("events_data").remove({"_id": {"$regex": ("^" + params.qstring.app_id + "_" + collectionNameWoPrefix + "_.*")}, "s": {$in: obj.list}}, {multi: true}, function(err3) {
if (err3) {
console.log(err3);
}
Expand All @@ -1196,7 +1196,7 @@ const processRequest = (params) => {
unsetUs["meta_v2." + obj.list[p]] = "";
}
//clears out meta data for segments
common.db.collection("events" + collectionNameWoPrefix).update({$or: my_query}, {$unset: unsetUs}, {multi: true}, function(err4) {
common.db.collection("events_data").update({"_id": {"$regex": ("^" + params.qstring.app_id + "_" + collectionNameWoPrefix + "_.*")}, $or: my_query}, {$unset: unsetUs}, {multi: true}, function(err4) {
if (err4) {
console.log(err4);
}
Expand Down Expand Up @@ -1240,7 +1240,6 @@ const processRequest = (params) => {
else {
resolve();
}

});
}
else {
Expand Down
11 changes: 7 additions & 4 deletions test/2.api/15.event.managment.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@ describe('Testing event settings', function() {

it('checking for segmentation in collections(test3)', function(done) {
var collectionNameWoPrefix = crypto.createHash('sha1').update("test3" + APP_ID).digest('hex');
testUtils.db.collection("events" + collectionNameWoPrefix).find({"s": {$in: ["my_segment"]}}).toArray(function(err, res) {
testUtils.db.collection("events_data").find({"_id": {"$regex": ("^" + APP_ID + "_" + collectionNameWoPrefix + "_.*")}, "s": {$in: ["my_segment"]}}).toArray(function(err, res) {
if (err) {
console.log(err);
}
if (res.length == 0) {
done();
}
Expand Down Expand Up @@ -465,7 +468,7 @@ describe('Testing event settings', function() {

it('checking for segmentation in collections(test3)', function(done) {
var collectionNameWoPrefix = crypto.createHash('sha1').update("test3" + APP_ID).digest('hex');
testUtils.db.collection("events" + collectionNameWoPrefix).find({"s": {$in: ["my_segment"]}}).toArray(function(err, res) {
testUtils.db.collection("events_data").find({"_id": {"$regex": ("^" + APP_ID + "_" + collectionNameWoPrefix + "_.*")}, "s": {$in: ["my_segment"]}}).toArray(function(err, res) {
if (res.length == 0) {
done();
}
Expand Down Expand Up @@ -516,7 +519,7 @@ describe('Testing event settings', function() {

it('checking for segmentation in collections(t1)', function(done) {
var collectionNameWoPrefix = crypto.createHash('sha1').update("t1" + APP_ID).digest('hex');
testUtils.db.collection("events" + collectionNameWoPrefix).find({"s": {$in: ["s"]}}).toArray(function(err, res) {
testUtils.db.collection("events_data").find({"_id": {"$regex": ("^" + APP_ID + "_" + collectionNameWoPrefix + "_.*")}, "s": {$in: ["s"]}}).toArray(function(err, res) {
if (res.length == 0) {
done();
}
Expand Down Expand Up @@ -676,7 +679,7 @@ describe('Testing event settings', function() {

it('checking for segmentation in collections(t5)', function(done) {
var collectionNameWoPrefix = crypto.createHash('sha1').update("t5" + APP_ID).digest('hex');
testUtils.db.collection("events" + collectionNameWoPrefix).find({"s": {$in: ["bad_segment"]}}).toArray(function(err, res) {
testUtils.db.collection("events_data").find({"_id": {"$regex": ("^" + APP_ID + "_" + collectionNameWoPrefix + "_.*")}, "s": {$in: ["bad_segment"]}}).toArray(function(err, res) {
if (res.length == 0) {
done();
}
Expand Down

0 comments on commit 1309cae

Please sign in to comment.