From fb7f10d63d35a12e2ab96168aac1532c50c82e2e Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 3 Nov 2015 12:27:15 -0500 Subject: [PATCH] closes #3821 --- src/topics/fork.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/topics/fork.js b/src/topics/fork.js index aefb2a88cd..fa4633fdd6 100644 --- a/src/topics/fork.js +++ b/src/topics/fork.js @@ -103,6 +103,9 @@ module.exports = function(Topics) { }, function(next) { async.parallel([ + function(next) { + updateCategoryPostCount(postData.tid, tid, next); + }, function(next) { Topics.decreasePostCount(postData.tid, next); }, @@ -132,6 +135,24 @@ module.exports = function(Topics) { }); }; + function updateCategoryPostCount(oldTid, tid, callback) { + Topics.getTopicsFields([oldTid, tid], ['cid'], function(err, topicData) { + if (err) { + return callback(err); + } + if (!topicData[0].cid || !topicData[1].cid) { + return callback(); + } + if (parseInt(topicData[0].cid, 10) === parseInt(topicData[1].cid, 10)) { + return callback(); + } + async.parallel([ + async.apply(db.incrObjectFieldBy, 'category:' + topicData[0].cid, 'post_count', -1), + async.apply(db.incrObjectFieldBy, 'category:' + topicData[1].cid, 'post_count', 1) + ], callback); + }); + } + function updateRecentTopic(tid, callback) { async.waterfall([ function(next) {