From 67ca1881bdbe1dba855a1bc62ddc7a45fd5e7491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 15 Jul 2017 16:24:46 -0400 Subject: [PATCH] closes #5831 --- src/categories/recentreplies.js | 29 ++++++++++++++++++++++++++--- src/topics/tools.js | 17 ++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index 38f7f0a087..193300dc0e 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -59,6 +59,25 @@ module.exports = function (Categories) { ], callback); }; + Categories.updateRecentTidForCid = function (cid, callback) { + async.waterfall([ + function (next) { + db.getSortedSetRevRange('cid:' + cid + ':pids', 0, 0, next); + }, + function (pid, next) { + pid = pid[0]; + posts.getPostField(pid, 'tid', next); + }, + function (tid, next) { + if (!parseInt(tid, 10)) { + return next(); + } + + Categories.updateRecentTid(cid, tid, next); + }, + ], callback); + }; + Categories.getRecentTopicReplies = function (categoryData, uid, callback) { if (!Array.isArray(categoryData) || !categoryData.length) { return callback(); @@ -180,8 +199,11 @@ module.exports = function (Categories) { Categories.moveRecentReplies = function (tid, oldCid, cid, callback) { callback = callback || function () {}; - updatePostCount(tid, oldCid, cid); + async.waterfall([ + function (next) { + updatePostCount(tid, oldCid, cid, next); + }, function (next) { topics.getPids(tid, next); }, @@ -212,7 +234,6 @@ module.exports = function (Categories) { }; function updatePostCount(tid, oldCid, newCid, callback) { - callback = callback || function () {}; async.waterfall([ function (next) { topics.getTopicField(tid, 'postcount', next); @@ -228,7 +249,9 @@ module.exports = function (Categories) { function (next) { db.incrObjectFieldBy('category:' + newCid, 'post_count', postCount, next); }, - ], next); + ], function (err) { + next(err); + }); }, ], callback); } diff --git a/src/topics/tools.js b/src/topics/tools.js index db112e9daa..fffecbd943 100644 --- a/src/topics/tools.js +++ b/src/topics/tools.js @@ -50,6 +50,9 @@ module.exports = function (Topics) { Topics[isDelete ? 'delete' : 'restore'](tid, uid, next); }, + function (next) { + categories.updateRecentTidForCid(topicData.cid, next); + }, function (next) { topicData.deleted = isDelete ? 1 : 0; @@ -261,7 +264,8 @@ module.exports = function (Topics) { db.sortedSetsRemove([ 'cid:' + topicData.cid + ':tids', 'cid:' + topicData.cid + ':tids:pinned', - 'cid:' + topicData.cid + ':tids:posts', // post count + 'cid:' + topicData.cid + ':tids:posts', + 'cid:' + topicData.cid + ':recent_tids', ], tid, next); }, function (next) { @@ -283,8 +287,9 @@ module.exports = function (Topics) { }, function (next) { oldCid = topic.cid; - categories.moveRecentReplies(tid, oldCid, cid); - + categories.moveRecentReplies(tid, oldCid, cid, next); + }, + function (next) { async.parallel([ function (next) { categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1, next); @@ -292,6 +297,12 @@ module.exports = function (Topics) { function (next) { categories.incrementCategoryFieldBy(cid, 'topic_count', 1, next); }, + function (next) { + categories.updateRecentTid(cid, tid, next); + }, + function (next) { + categories.updateRecentTidForCid(oldCid, next); + }, function (next) { Topics.setTopicFields(tid, { cid: cid,