From 0b3656f34cf150f5ebc3a8e31efe9b56bfe2f8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 27 Apr 2017 16:40:01 -0400 Subject: [PATCH] fix timeouts on category.purge when there are 20k groups --- src/categories/delete.js | 2 +- src/groups/delete.js | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/categories/delete.js b/src/categories/delete.js index 4aad25846f..d5da434c26 100644 --- a/src/categories/delete.js +++ b/src/categories/delete.js @@ -58,7 +58,7 @@ module.exports = function (Categories) { ], next); }, function (next) { - async.each(privileges.privilegeList, function (privilege, next) { + async.eachSeries(privileges.privilegeList, function (privilege, next) { groups.destroy('cid:' + cid + ':privileges:' + privilege, next); }, next); }, diff --git a/src/groups/delete.js b/src/groups/delete.js index e05eff6370..1a9f91ce0a 100644 --- a/src/groups/delete.js +++ b/src/groups/delete.js @@ -4,6 +4,7 @@ var async = require('async'); var plugins = require('../plugins'); var utils = require('../utils'); var db = require('./../database'); +var batch = require('../batch'); module.exports = function (Groups) { Groups.destroy = function (groupName, callback) { @@ -30,14 +31,14 @@ module.exports = function (Groups) { async.apply(db.delete, 'group:' + groupName + ':owners'), async.apply(db.deleteObjectField, 'groupslug:groupname', utils.slugify(groupName)), function (next) { - db.getSortedSetRange('groups:createtime', 0, -1, function (err, groups) { - if (err) { - return next(err); - } - async.each(groups, function (group, next) { - db.sortedSetRemove('group:' + group + ':members', groupName, next); - }, 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); }, ], function (err) { if (err) {