mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Upgrade tests tools and lint migrations and scripts (part 2) (#9998)
* upgrade gulp-babel * upgrade babel-eslint * upgrade eslint-friendly-formatter * start upgrading chai * start to upgrade eslint * restore skipped tests * start to upgrqde monk * fix linting and remove unused file * fix mocha notifications, and common tests * fix unit tests * start to fix initrgration tests * more integration tests fixes * upgrade monk to latest version * lint /scripts * migrations: start moving to /archive unused migrations and run eslint with --fix * lint migrations * fix more integration tests * fix test
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Remove deleted accounts from groups
|
||||
*/
|
||||
|
||||
let mongo = require('mongoskin');
|
||||
let async = require('async');
|
||||
|
||||
let dbserver = 'url';
|
||||
let dbname = 'dbname';
|
||||
let countGroups = 0;
|
||||
let countUsers = 0;
|
||||
|
||||
let db = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`);
|
||||
let dbUsers = db.collection('users');
|
||||
let dbGroups = db.collection('groups');
|
||||
|
||||
console.log('Begins work on db');
|
||||
|
||||
function findGroups (gt) {
|
||||
let query = {};
|
||||
if (gt) query._id = {$gt: gt};
|
||||
|
||||
console.log(query);
|
||||
|
||||
dbGroups.find(query, {
|
||||
fields: {_id: 1, members: 1},
|
||||
limit: 10000,
|
||||
sort: {
|
||||
_id: 1,
|
||||
},
|
||||
}).toArray(function (err, groups) {
|
||||
if (err) throw err;
|
||||
|
||||
let lastGroup = null;
|
||||
if (groups.length === 10000) {
|
||||
lastGroup = groups[groups.length - 1];
|
||||
}
|
||||
|
||||
async.eachLimit(groups, 3, function (group, cb1) {
|
||||
countGroups++;
|
||||
console.log('Group: ', countGroups, group._id);
|
||||
|
||||
let members = group.members;
|
||||
|
||||
// Remove users who deleted their account
|
||||
async.eachLimit(members, 15, function (member, cb2) {
|
||||
dbUsers.findOne({_id: member}, {fields: {_id: 1}}, function (err, user) {
|
||||
if (err) return cb2(err);
|
||||
|
||||
if (!user) {
|
||||
countUsers++;
|
||||
console.log('User removed n. ', countUsers, 'user id ', member, 'group id ', group._id);
|
||||
|
||||
dbGroups.update({
|
||||
_id: group._id,
|
||||
}, {
|
||||
$pull: {members: member},
|
||||
$inc: {memberCount: -1},
|
||||
}, {
|
||||
multi: false,
|
||||
}, function (err, res) {
|
||||
if (err) return cb2(err);
|
||||
|
||||
console.log('Updated: ', res);
|
||||
return cb2();
|
||||
});
|
||||
} else {
|
||||
cb2();
|
||||
}
|
||||
});
|
||||
}, function (err) {
|
||||
if (err) return cb1(err);
|
||||
|
||||
cb1();
|
||||
});
|
||||
}, function (err) {
|
||||
if (err) throw err;
|
||||
|
||||
if (lastGroup && lastGroup._id) {
|
||||
findGroups(lastGroup._id);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
findGroups();
|
||||
Reference in New Issue
Block a user