clean up, radix

This commit is contained in:
barisusakli
2014-03-14 19:22:56 -04:00
parent 1354739d19
commit 42f42adfaf

View File

@@ -81,13 +81,7 @@ module.exports = function(User) {
}; };
function deletePosts(uid, callback) { function deletePosts(uid, callback) {
db.getSortedSetRange('uid:' + uid + ':posts', 0, -1, function(err, pids) { deleteSortedSetElements('uid:' + uid + ':posts', deletePost, callback);
if (err) {
return callback(err);
}
async.each(pids, deletePost, callback);
});
} }
function deletePost(pid, callback) { function deletePost(pid, callback) {
@@ -196,11 +190,16 @@ module.exports = function(User) {
} }
function deleteTopics(uid, callback) { function deleteTopics(uid, callback) {
db.getSortedSetRange('uid:' + uid + ':topics', 0, -1, function(err, tids) { deleteSortedSetElements('uid:' + uid + ':topics', deleteTopic, callback);
}
function deleteSortedSetElements(set, deleteMethod, callback) {
db.getSortedSetRange(set, 0, -1, function(err, ids) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
async.each(tids, deleteTopic, callback);
async.each(ids, deleteMethod, callback);
}); });
} }
@@ -253,7 +252,7 @@ module.exports = function(User) {
return callback(err); return callback(err);
} }
if (parseInt(topicData.deleted) === 0) { if (parseInt(topicData.deleted, 10) === 0) {
db.decrObjectField('global', 'topicCount', callback); db.decrObjectField('global', 'topicCount', callback);
} else { } else {
callback(); callback();