Skip to content

Commit 0ef7c03

Browse files
committed
Changes for countly_single_app_expireDataBatches.js
1 parent 2cf3532 commit 0ef7c03

File tree

2 files changed

+334
-35
lines changed

2 files changed

+334
-35
lines changed

bin/scripts/expire-data/countly_single_app_expireDataBatches.js

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ var timeout = 500; //timeout in miliseconds between deletion. (One second ====
3939

4040

4141
var async = require('async'),
42-
crypto = require('crypto'),
4342
Promise = require("bluebird"),
4443
plugins = require('../../../plugins/pluginManager.js');
4544

@@ -109,6 +108,9 @@ function eventIterator(fr, done) {
109108
console.log('Processing range: ' + JSON.stringify({"ts": {"$gte": fr.start, "$lt": fr.end}}) + ' for ' + fr.collection);
110109
var query = {};
111110
query["ts"] = {"$gte": fr.start, "$lt": fr.end};
111+
if (collection === 'drill_events') {
112+
query["a"] = APP_ID;
113+
}
112114
if (fr.query) {
113115
for (var key in fr.query) {
114116
query[key] = fr.query.key;
@@ -242,41 +244,13 @@ function processDrillCollection(collection, seconds, callback) {
242244
}
243245
}
244246

245-
function processDrillCollections(db, drill_db, callback) {
247+
function processDrillCollections(drill_db, callback) {
246248
if (process && process.drill_events) {
247-
var collections = [];
248-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_session" + APP_ID).digest('hex')});
249-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_crash" + APP_ID).digest('hex')});
250-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_view" + APP_ID).digest('hex')});
251-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_action" + APP_ID).digest('hex')});
252-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_apm_device" + APP_ID).digest('hex')});
253-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_apm_network" + APP_ID).digest('hex')});
254-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_nps" + APP_ID).digest('hex')});
255-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_survey" + APP_ID).digest('hex')});
256-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_push_action" + APP_ID).digest('hex')});
257-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_star_rating" + APP_ID).digest('hex')});
258-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_push_sent" + APP_ID).digest('hex')});
259-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update("[CLY]_consent" + APP_ID).digest('hex')});
260-
db.collection("events").findOne({'_id': db.ObjectID(APP_ID)}, {list: 1}, function(err, eventData) {
261-
if (eventData && eventData.list) {
262-
for (var i = 0; i < eventData.list.length; i++) {
263-
collections.push({'db': drill_db, 'collection': "drill_events" + crypto.createHash('sha1').update(eventData.list[i] + APP_ID).digest('hex')});
264-
}
249+
processDrillCollection({"collection": "drill_events", db: drill_db}, false, function(err) {
250+
if (err) {
251+
console.log("ERROR: Error while processing drill collection: drill_events");
265252
}
266-
267-
async.eachSeries(collections, function(collection, done) {
268-
processDrillCollection(collection, false, function(err) {
269-
if (err) {
270-
console.log("ERROR: Error while processing drill collection: " + collection.collection);
271-
}
272-
done(err);
273-
});
274-
}, function(err) {
275-
if (err) {
276-
console.log("ERROR: Error processing collections.");
277-
}
278-
callback(err);
279-
});
253+
callback(err);
280254
});
281255
}
282256
else {
@@ -292,7 +266,7 @@ Promise.all([plugins.dbConnection("countly"), plugins.dbConnection("countly_dril
292266
db_drill.close();
293267
}
294268
else {
295-
processDrillCollections(db, db_drill, function() {
269+
processDrillCollections(db_drill, function() {
296270
var processCols = [];
297271
for (var key in process) {
298272
if (key !== 'drill_events') {

0 commit comments

Comments
 (0)