dont load post data again

shorter async.parallel
v1.18.x
Barış Soner Uşaklı 6 years ago
parent d3e4daebec
commit 4caaa046d7

@ -75,34 +75,18 @@ module.exports = function (Posts) {
if (!postData) { if (!postData) {
return callback(); return callback();
} }
plugins.fireHook('filter:post.purge', { pid: pid, uid: uid }, next); plugins.fireHook('filter:post.purge', { post: postData, pid: pid, uid: uid }, next);
}, },
function (data, next) { function (data, next) {
async.parallel([ async.parallel([
function (next) { async.apply(deletePostFromTopicUserNotification, postData),
deletePostFromTopicUserNotification(pid, next); async.apply(deletePostFromCategoryRecentPosts, pid),
}, async.apply(deletePostFromUsersBookmarks, pid),
function (next) { async.apply(deletePostFromUsersVotes, pid),
deletePostFromCategoryRecentPosts(pid, next); async.apply(deletePostFromReplies, postData),
}, async.apply(deletePostFromGroups, postData),
function (next) { async.apply(db.sortedSetsRemove, ['posts:pid', 'posts:votes', 'posts:flagged'], pid),
deletePostFromUsersBookmarks(pid, next); ], err => next(err));
},
function (next) {
deletePostFromUsersVotes(pid, next);
},
function (next) {
deletePostFromReplies(pid, next);
},
function (next) {
deletePostFromGroups(pid, next);
},
function (next) {
db.sortedSetsRemove(['posts:pid', 'posts:votes', 'posts:flagged'], pid, next);
},
], function (err) {
next(err);
});
}, },
function (next) { function (next) {
plugins.fireHook('action:post.purge', { post: postData, uid: uid }); plugins.fireHook('action:post.purge', { post: postData, uid: uid });
@ -111,57 +95,33 @@ module.exports = function (Posts) {
], callback); ], callback);
}; };
function deletePostFromTopicUserNotification(pid, callback) { function deletePostFromTopicUserNotification(postData, callback) {
var postData;
async.waterfall([ async.waterfall([
function (next) { function (next) {
Posts.getPostFields(pid, ['tid', 'uid'], next);
},
function (_postData, next) {
postData = _postData;
db.sortedSetsRemove([ db.sortedSetsRemove([
'tid:' + postData.tid + ':posts', 'tid:' + postData.tid + ':posts',
'tid:' + postData.tid + ':posts:votes', 'tid:' + postData.tid + ':posts:votes',
'uid:' + postData.uid + ':posts', 'uid:' + postData.uid + ':posts',
], pid, next); ], postData.pid, next);
}, },
function (next) { function (next) {
topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned'], next); topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned'], next);
}, },
function (topicData, next) { function (topicData, next) {
async.parallel([ const tasks = [
function (next) { async.apply(db.decrObjectField, 'global', 'postCount'),
db.decrObjectField('global', 'postCount', next); async.apply(db.decrObjectField, 'category:' + topicData.cid, 'post_count'),
}, async.apply(topics.decreasePostCount, postData.tid),
function (next) { async.apply(topics.updateTeaser, postData.tid),
db.decrObjectField('category:' + topicData.cid, 'post_count', next); async.apply(topics.updateLastPostTimeFromLastPid, postData.tid),
}, async.apply(db.sortedSetIncrBy, 'tid:' + postData.tid + ':posters', -1, postData.uid),
function (next) { async.apply(user.incrementUserPostCountBy, postData.uid, -1),
topics.decreasePostCount(postData.tid, next); async.apply(notifications.rescind, 'new_post:tid:' + postData.tid + ':pid:' + postData.pid + ':uid:' + postData.uid),
}, ];
function (next) {
topics.updateTeaser(postData.tid, next);
},
function (next) {
topics.updateLastPostTimeFromLastPid(postData.tid, next);
},
function (next) {
if (!topicData.pinned) { if (!topicData.pinned) {
db.sortedSetIncrBy('cid:' + topicData.cid + ':tids:posts', -1, postData.tid, next); tasks.push(async.apply(db.sortedSetIncrBy, 'cid:' + topicData.cid + ':tids:posts', -1, postData.tid));
} else {
next();
} }
}, async.parallel(tasks, next);
function (next) {
db.sortedSetIncrBy('tid:' + postData.tid + ':posters', -1, postData.uid, next);
},
function (next) {
user.incrementUserPostCountBy(postData.uid, -1, next);
},
function (next) {
notifications.rescind('new_post:tid:' + postData.tid + ':pid:' + pid + ':uid:' + postData.uid, next);
},
], next);
}, },
], function (err) { ], function (err) {
callback(err); callback(err);
@ -211,11 +171,8 @@ module.exports = function (Posts) {
async.parallel([ async.parallel([
function (next) { function (next) {
const upvoterSets = results.upvoters.map(uid => 'uid:' + uid + ':upvote'); const upvoterSets = results.upvoters.map(uid => 'uid:' + uid + ':upvote');
db.sortedSetsRemove(upvoterSets, pid, next);
},
function (next) {
const downvoterSets = results.downvoters.map(uid => 'uid:' + uid + ':downvote'); const downvoterSets = results.downvoters.map(uid => 'uid:' + uid + ':downvote');
db.sortedSetsRemove(downvoterSets, pid, next); db.sortedSetsRemove(upvoterSets.concat(downvoterSets), pid, next);
}, },
function (next) { function (next) {
db.deleteAll(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], next); db.deleteAll(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], next);
@ -225,38 +182,28 @@ module.exports = function (Posts) {
], callback); ], callback);
} }
function deletePostFromReplies(pid, callback) { function deletePostFromReplies(postData, callback) {
async.waterfall([ if (!parseInt(postData.toPid, 10)) {
function (next) { return setImmediate(callback);
Posts.getPostField(pid, 'toPid', next);
},
function (toPid, next) {
if (!parseInt(toPid, 10)) {
return callback(null);
} }
async.parallel([ async.parallel([
async.apply(db.sortedSetRemove, 'pid:' + toPid + ':replies', pid), async.apply(db.sortedSetRemove, 'pid:' + postData.toPid + ':replies', postData.pid),
async.apply(db.decrObjectField, 'post:' + toPid, 'replies'), async.apply(db.decrObjectField, 'post:' + postData.toPid, 'replies'),
], next);
},
], callback); ], callback);
} }
function deletePostFromGroups(pid, callback) { function deletePostFromGroups(postData, callback) {
if (!parseInt(postData.uid, 10)) {
return setImmediate(callback);
}
async.waterfall([ async.waterfall([
function (next) { function (next) {
Posts.getPostField(pid, 'uid', next); groups.getUserGroupMembership('groups:visible:createtime', [postData.uid], next);
},
function (uid, next) {
if (!parseInt(uid, 10)) {
return callback();
}
groups.getUserGroupMembership('groups:visible:createtime', [uid], next);
}, },
function (groupNames, next) { function (groupNames, next) {
groupNames = groupNames[0]; groupNames = groupNames[0];
const keys = groupNames.map(groupName => 'group:' + groupName + ':member:pids'); const keys = groupNames.map(groupName => 'group:' + groupName + ':member:pids');
db.sortedSetsRemove(keys, pid, next); db.sortedSetsRemove(keys, postData.pid, next);
}, },
], callback); ], callback);
} }

Loading…
Cancel
Save