Skip to content

Node.js based forum software built for the modern web

closes #5831

Barış Soner Uşaklı67ca1881bdbe
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,