Skip to content

Commit d18f458

Browse files
authored
Merge pull request #5732 from Countly/SER-2118
[SER-2118] Improve script to fetch event deletion list from countly.events and drill_meta
2 parents ce6190d + c3a4498 commit d18f458

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

bin/scripts/expire-data/delete_custom_events_regex.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88

9-
const { ObjectId } = require('mongodb');
109
const pluginManager = require('../../../plugins/pluginManager.js');
1110
const common = require('../../../api/utils/common.js');
1211
const drillCommon = require('../../../plugins/drill/api/common.js');
@@ -25,7 +24,7 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
2524

2625
//GET APP
2726
try {
28-
const app = await countlyDb.collection("apps").findOne({_id: ObjectId(APP_ID)}, {_id: 1, name: 1});
27+
const app = await countlyDb.collection("apps").findOne({_id: countlyDb.ObjectID(APP_ID)}, {_id: 1, name: 1});
2928
console.log("App:", app.name);
3029
//GET EVENTS
3130
var events = [];
@@ -51,6 +50,27 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
5150
}
5251
]).toArray();
5352
events = events.length ? events[0].list : [];
53+
const metaEvents = await drillDb.collection("drill_meta").aggregate([
54+
{
55+
$match: {
56+
'app_id': app._id + "",
57+
"type": "e",
58+
"e": { $regex: regex, $options: CASE_INSENSITIVE ? "i" : "", $nin: events }
59+
}
60+
},
61+
{
62+
$group: {
63+
_id: "$e"
64+
}
65+
},
66+
{
67+
$project: {
68+
_id: 0,
69+
e: "$_id"
70+
}
71+
}
72+
]).toArray();
73+
events = events.concat(metaEvents.map(e => e.e));
5474
}
5575
catch (err) {
5676
close("Invalid regex");
@@ -86,6 +106,7 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
86106
close(err);
87107
}
88108

109+
89110
async function deleteDrillEvents(appId, events) {
90111
for (let i = 0; i < events.length; i++) {
91112
var collectionName = drillCommon.getCollectionName(events[i], appId);

0 commit comments

Comments
 (0)