From a49a9a07b388399145ee924b610baef6eb1d00d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 2 Jun 2017 18:19:06 -0400 Subject: [PATCH] refactor groups.delete --- src/groups/delete.js | 54 ++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/groups/delete.js b/src/groups/delete.js index 4d5fa6b4c0..b0203aa60e 100644 --- a/src/groups/delete.js +++ b/src/groups/delete.js @@ -20,26 +20,31 @@ module.exports = function (Groups) { groupObj = groupsData[0]; async.parallel([ - async.apply(db.delete, 'group:' + groupName), - async.apply(db.sortedSetRemove, 'groups:createtime', groupName), - async.apply(db.sortedSetRemove, 'groups:visible:createtime', groupName), - async.apply(db.sortedSetRemove, 'groups:visible:memberCount', groupName), - async.apply(db.sortedSetRemove, 'groups:visible:name', groupName.toLowerCase() + ':' + groupName), - async.apply(db.delete, 'group:' + groupName + ':members'), - async.apply(db.delete, 'group:' + groupName + ':pending'), - async.apply(db.delete, 'group:' + groupName + ':invited'), - async.apply(db.delete, 'group:' + groupName + ':owners'), - async.apply(db.delete, 'group:' + groupName + ':member:pids'), - async.apply(db.deleteObjectField, 'groupslug:groupname', utils.slugify(groupName)), function (next) { - batch.processSortedSet('groups:createtime', function (groupNames, next) { - var keys = groupNames.map(function (group) { - return 'group:' + group + ':members'; - }); - db.sortedSetsRemove(keys, groupName, next); - }, { - batch: 500, - }, next); + db.deleteAll([ + 'group:' + groupName, + 'group:' + groupName + ':members', + 'group:' + groupName + ':pending', + 'group:' + groupName + ':invited', + 'group:' + groupName + ':owners', + 'group:' + groupName + ':member:pids', + ], next); + }, + function (next) { + db.sortedSetsRemove([ + 'groups:createtime', + 'groups:visible:createtime', + 'groups:visible:memberCount', + ], groupName, next); + }, + function (next) { + db.sortedSetRemove('groups:visible:name', groupName.toLowerCase() + ':' + groupName, next); + }, + function (next) { + db.deleteObjectField('groupslug:groupname', utils.slugify(groupName), next); + }, + function (next) { + removeGroupFromOtherGroups(groupName, next); }, ], function (err) { next(err); @@ -52,4 +57,15 @@ module.exports = function (Groups) { }, ], callback); }; + + function removeGroupFromOtherGroups(groupName, callback) { + batch.processSortedSet('groups:createtime', function (groupNames, next) { + var keys = groupNames.map(function (group) { + return 'group:' + group + ':members'; + }); + db.sortedSetsRemove(keys, groupName, next); + }, { + batch: 500, + }, callback); + } };