Cache the number of replies in the post object. See #5050.

https://github.com/NodeBB/NodeBB/pull/5050#pullrequestreview-4248269
This commit is contained in:
Ben Lubar
2016-10-14 09:58:31 -05:00
parent 5d66811213
commit 123c66e3ec
5 changed files with 21 additions and 25 deletions

View File

@@ -86,7 +86,10 @@ module.exports = function (Posts) {
if (!postData.toPid) {
return next(null);
}
db.sortedSetAdd('pid:' + postData.toPid + ':replies', timestamp, postData.pid, next);
async.parallel([
async.apply(db.sortedSetAdd, 'pid:' + postData.toPid + ':replies', timestamp, postData.pid),
async.apply(db.incrObjectField, 'post:' + postData.toPid, 'replies')
], next);
},
function (next) {
db.incrObjectField('global', 'postCount', next);