mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 16:35:47 +01:00
optimized user.delete
This commit is contained in:
@@ -29,6 +29,10 @@ module.exports = function(db, module) {
|
||||
});
|
||||
};
|
||||
|
||||
module.setsRemove = function(keys, value, callback) {
|
||||
throw new Error('not-implemented');
|
||||
};
|
||||
|
||||
module.isSetMember = function(key, value, callback) {
|
||||
module.getListRange(key, 0, -1, function(err, set) {
|
||||
callback(err, set.indexOf(value) !== -1);
|
||||
|
||||
@@ -69,6 +69,27 @@ module.exports = function(db, module) {
|
||||
db.collection('objects').update({_key: key}, {$pullAll: {members: value}}, callback);
|
||||
};
|
||||
|
||||
module.setsRemove = function(keys, value, callback) {
|
||||
callback = callback || helpers.noop;
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return callback();
|
||||
}
|
||||
value = helpers.valueToString(value);
|
||||
|
||||
var bulk = db.collection('objects').initializeUnorderedBulkOp();
|
||||
|
||||
for(var i=0; i<keys.length; ++i) {
|
||||
bulk.find({_key: keys[i]}).updateOne({$pull: {
|
||||
members: value
|
||||
}});
|
||||
}
|
||||
|
||||
bulk.execute(function(err, res) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
module.isSetMember = function(key, value, callback) {
|
||||
value = helpers.valueToString(value);
|
||||
|
||||
|
||||
@@ -23,6 +23,18 @@ module.exports = function(redisClient, module) {
|
||||
redisClient.srem(key, value, callback);
|
||||
};
|
||||
|
||||
module.setsRemove = function(keys, value, callback) {
|
||||
callback = callback || function() {};
|
||||
|
||||
var multi = redisClient.multi();
|
||||
for(var i=0; i<keys.length; ++i) {
|
||||
multi.srem(keys[i], value);
|
||||
}
|
||||
multi.exec(function(err, res) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
module.isSetMember = function(key, value, callback) {
|
||||
redisClient.sismember(key, value, function(err, result) {
|
||||
if(err) {
|
||||
|
||||
@@ -6,8 +6,8 @@ var async = require('async'),
|
||||
user = require('../user'),
|
||||
topics = require('../topics'),
|
||||
groups = require('../groups'),
|
||||
plugins = require('../plugins');
|
||||
|
||||
plugins = require('../plugins'),
|
||||
batch = require('../batch');
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
@@ -34,13 +34,13 @@ module.exports = function(User) {
|
||||
}
|
||||
|
||||
function deleteSortedSetElements(set, deleteMethod, callback) {
|
||||
db.getSortedSetRange(set, 0, -1, function(err, ids) {
|
||||
batch.processSortedSet(set, function(err, ids, next) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.each(ids, deleteMethod, callback);
|
||||
});
|
||||
async.eachLimit(ids, 10, deleteMethod, next);
|
||||
}, {alwaysStartAt: 0}, callback);
|
||||
}
|
||||
|
||||
User.deleteAccount = function(uid, callback) {
|
||||
@@ -60,49 +60,18 @@ module.exports = function(User) {
|
||||
db.deleteObjectField('email:uid', userData.email.toLowerCase(), next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('uid:' + uid + ':notifications:read', next);
|
||||
db.sortedSetsRemove(['users:joindate', 'users:postcount', 'users:reputation'], uid, next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('uid:' + uid + ':notifications:unread', next);
|
||||
},
|
||||
function(next) {
|
||||
db.sortedSetRemove('users:joindate', uid, next);
|
||||
},
|
||||
function(next) {
|
||||
db.sortedSetRemove('users:postcount', uid, next);
|
||||
},
|
||||
function(next) {
|
||||
db.sortedSetRemove('users:reputation', uid, next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('uid:' + uid + ':favourites', next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('user:' + uid + ':settings', next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('uid:' + uid + ':topics', next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('uid:' + uid + ':posts', next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('uid:' + uid + ':chats', next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('uid:' + uid + ':chats:unread', next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('uid:' + uid + ':ip', next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('uid:' + uid + ':upvote', next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('uid:' + uid + ':downvote', next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('uid:' + uid + ':ignored:cids', next);
|
||||
var keys = [
|
||||
'uid:' + uid + ':notifications:read', 'uid:' + uid + ':notifications:unread',
|
||||
'uid:' + uid + ':favourites', 'user:' + uid + ':settings',
|
||||
'uid:' + uid + ':topics', 'uid:' + uid + ':posts',
|
||||
'uid:' + uid + ':chats', 'uid:' + uid + ':chats:unread',
|
||||
'uid:' + uid + ':ip', 'uid:' + uid + ':upvote', 'uid:' + uid + ':downvote',
|
||||
'uid:' + uid + ':ignored:cids'
|
||||
];
|
||||
db.deleteAll(keys, next);
|
||||
},
|
||||
function(next) {
|
||||
deleteUserFromFollowers(uid, next);
|
||||
@@ -120,13 +89,7 @@ module.exports = function(User) {
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.delete('followers:' + uid, next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('following:' + uid, next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('user:' + uid, next);
|
||||
db.deleteAll(['followers:' + uid, 'following:' + uid, 'user:' + uid], next);
|
||||
},
|
||||
function(next) {
|
||||
db.decrObjectField('global', 'userCount', next);
|
||||
@@ -142,9 +105,11 @@ module.exports = function(User) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.each(uids, function(theiruid, next) {
|
||||
db.setRemove('following:' + theiruid, uid, next);
|
||||
}, callback);
|
||||
var sets = uids.map(function(uid) {
|
||||
return 'following:' + uid;
|
||||
});
|
||||
|
||||
db.setsRemove(sets, uid, callback);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user