From fde44cb9b9be8defed68099e2d730b7acf2439d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 17 Mar 2018 19:55:23 -0400 Subject: [PATCH] pass array to groups.destroy pass array to db.sortedSetRemove --- src/categories/delete.js | 6 +++--- src/user/notifications.js | 14 ++++---------- test/database/sorted.js | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/categories/delete.js b/src/categories/delete.js index 87ae9813d9..4e3a7060ce 100644 --- a/src/categories/delete.js +++ b/src/categories/delete.js @@ -58,9 +58,9 @@ module.exports = function (Categories) { ], next); }, function (next) { - async.eachSeries(privileges.privilegeList, function (privilege, next) { - groups.destroy('cid:' + cid + ':privileges:' + privilege, next); - }, next); + groups.destroy(privileges.privilegeList.map(function (privilege) { + return 'cid:' + cid + ':privileges:' + privilege; + }), next); }, ], function (err) { callback(err); diff --git a/src/user/notifications.js b/src/user/notifications.js index 04bc0fae9f..851a2d2e94 100644 --- a/src/user/notifications.js +++ b/src/user/notifications.js @@ -96,16 +96,10 @@ function deleteUserNids(nids, uid, callback) { if (!nids.length) { return setImmediate(callback); } - async.parallel([ - function (next) { - db.sortedSetRemove('uid:' + uid + ':notifications:read', nids, next); - }, - function (next) { - db.sortedSetRemove('uid:' + uid + ':notifications:unread', nids, next); - }, - ], function (err) { - callback(err); - }); + db.sortedSetRemove([ + 'uid:' + uid + ':notifications:read', + 'uid:' + uid + ':notifications:unread', + ], nids, callback); } function getNotifications(uid, start, stop, callback) { diff --git a/test/database/sorted.js b/test/database/sorted.js index f07eee3008..948ab29f32 100644 --- a/test/database/sorted.js +++ b/test/database/sorted.js @@ -678,6 +678,26 @@ describe('Sorted Set methods', function () { }); }); }); + + it('should remove multiple values from multiple keys', function (done) { + db.sortedSetAdd('multiTest5', [1], ['one'], function (err) { + assert.ifError(err); + db.sortedSetAdd('multiTest6', [2], ['two'], function (err) { + assert.ifError(err); + db.sortedSetAdd('multiTest7', [3], ['three'], function (err) { + assert.ifError(err); + db.sortedSetRemove(['multiTest5', 'multiTest6', 'multiTest7'], ['one', 'two', 'three'], function (err) { + assert.ifError(err); + db.getSortedSetsMembers(['multiTest5', 'multiTest6', 'multiTest7'], function (err, members) { + assert.ifError(err); + assert.deepEqual(members, [[], [], []]); + done(); + }); + }); + }); + }); + }); + }); }); describe('sortedSetsRemove()', function () {