From cb1920d45a26768d4f10493c32736996e3adcd97 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 29 Apr 2016 13:34:49 -0400 Subject: [PATCH] properly fixing #4583 --- src/posts/flags.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/posts/flags.js b/src/posts/flags.js index 2334032ddd..2590d68811 100644 --- a/src/posts/flags.js +++ b/src/posts/flags.js @@ -85,10 +85,24 @@ module.exports = function(Posts) { ], pid, next); }); }, + function(next) { + async.series([ + function(next) { + db.getSortedSetRange('pid:' + pid + ':flag:uids', 0, -1, function(err, uids) { + async.each(uids, function(uid, next) { + var nid = 'post_flag:' + pid + ':uid:' + uid; + async.parallel([ + async.apply(db.delete, 'notifications:' + nid), + async.apply(db.sortedSetRemove, 'notifications', 'post_flag:' + pid + ':uid:' + uid) + ], next); + }, next); + }); + }, + async.apply(db.delete, 'pid:' + pid + ':flag:uids') + ], next); + }, async.apply(db.deleteObjectField, 'post:' + pid, 'flags'), - async.apply(db.delete, 'pid:' + pid + ':flag:uids'), - async.apply(db.delete, 'pid:' + pid + ':flag:uid:reason'), - async.apply(db.sortedSetRemove, 'notifications', 'post_flag:' + pid + ':uid:' + uid) + async.apply(db.delete, 'pid:' + pid + ':flag:uid:reason') ], function(err) { callback(err); });