fix: #7788, fix on topic move and new post

v1.18.x
Baris Usakli 6 years ago
parent 053ff510bb
commit 8bf40d04c9

@ -37,7 +37,7 @@ module.exports = function (Categories) {
};
Categories.updateRecentTidForCid = async function (cid) {
let recentTid;
let postData;
let topicData;
let index = 0;
do {
@ -46,16 +46,16 @@ module.exports = function (Categories) {
if (!pids.length) {
return;
}
recentTid = await posts.getPostField(pids[0], 'tid');
if (!recentTid) {
return;
postData = await posts.getPostFields(pids[0], ['tid', 'deleted']);
if (postData && postData.tid && !postData.deleted) {
topicData = await topics.getTopicData(postData.tid);
}
topicData = await topics.getTopicData(recentTid);
index += 1;
} while (!topicData || topicData.deleted);
if (recentTid) {
await Categories.updateRecentTid(cid, recentTid);
if (postData && postData.tid) {
await Categories.updateRecentTid(cid, postData.tid);
}
};

@ -169,11 +169,11 @@ module.exports = function (Categories) {
const promises = [
db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid),
db.incrObjectField('category:' + cid, 'post_count'),
Categories.updateRecentTid(cid, postData.tid),
];
if (!pinned) {
promises.push(db.sortedSetIncrBy('cid:' + cid + ':tids:posts', 1, postData.tid));
}
await Promise.all(promises);
await Categories.updateRecentTidForCid(cid);
};
};

@ -207,7 +207,7 @@ module.exports = function (Topics) {
await Promise.all([
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1),
categories.incrementCategoryFieldBy(cid, 'topic_count', 1),
categories.updateRecentTid(cid, tid),
categories.updateRecentTidForCid(cid),
categories.updateRecentTidForCid(oldCid),
Topics.setTopicFields(tid, {
cid: cid,

Loading…
Cancel
Save