mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #7788, fix on topic move and new post
This commit is contained in:
@@ -37,7 +37,7 @@ module.exports = function (Categories) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Categories.updateRecentTidForCid = async function (cid) {
|
Categories.updateRecentTidForCid = async function (cid) {
|
||||||
let recentTid;
|
let postData;
|
||||||
let topicData;
|
let topicData;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
do {
|
do {
|
||||||
@@ -46,16 +46,16 @@ module.exports = function (Categories) {
|
|||||||
if (!pids.length) {
|
if (!pids.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
recentTid = await posts.getPostField(pids[0], 'tid');
|
postData = await posts.getPostFields(pids[0], ['tid', 'deleted']);
|
||||||
if (!recentTid) {
|
|
||||||
return;
|
if (postData && postData.tid && !postData.deleted) {
|
||||||
|
topicData = await topics.getTopicData(postData.tid);
|
||||||
}
|
}
|
||||||
topicData = await topics.getTopicData(recentTid);
|
|
||||||
index += 1;
|
index += 1;
|
||||||
} while (!topicData || topicData.deleted);
|
} while (!topicData || topicData.deleted);
|
||||||
|
|
||||||
if (recentTid) {
|
if (postData && postData.tid) {
|
||||||
await Categories.updateRecentTid(cid, recentTid);
|
await Categories.updateRecentTid(cid, postData.tid);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -169,11 +169,11 @@ module.exports = function (Categories) {
|
|||||||
const promises = [
|
const promises = [
|
||||||
db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid),
|
db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid),
|
||||||
db.incrObjectField('category:' + cid, 'post_count'),
|
db.incrObjectField('category:' + cid, 'post_count'),
|
||||||
Categories.updateRecentTid(cid, postData.tid),
|
|
||||||
];
|
];
|
||||||
if (!pinned) {
|
if (!pinned) {
|
||||||
promises.push(db.sortedSetIncrBy('cid:' + cid + ':tids:posts', 1, postData.tid));
|
promises.push(db.sortedSetIncrBy('cid:' + cid + ':tids:posts', 1, postData.tid));
|
||||||
}
|
}
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
await Categories.updateRecentTidForCid(cid);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ module.exports = function (Topics) {
|
|||||||
await Promise.all([
|
await Promise.all([
|
||||||
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1),
|
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1),
|
||||||
categories.incrementCategoryFieldBy(cid, 'topic_count', 1),
|
categories.incrementCategoryFieldBy(cid, 'topic_count', 1),
|
||||||
categories.updateRecentTid(cid, tid),
|
categories.updateRecentTidForCid(cid),
|
||||||
categories.updateRecentTidForCid(oldCid),
|
categories.updateRecentTidForCid(oldCid),
|
||||||
Topics.setTopicFields(tid, {
|
Topics.setTopicFields(tid, {
|
||||||
cid: cid,
|
cid: cid,
|
||||||
|
|||||||
Reference in New Issue
Block a user