fix: #10594, move counter code (#11529)

instead of updating counters one by one on each topic move, update them once after all topics are moved, use zcard instead of incr/decr
This commit is contained in:
Barış Soner Uşaklı
2023-04-27 20:27:42 -04:00
committed by GitHub
parent 01669fa54e
commit 5607e5bccb
4 changed files with 21 additions and 18 deletions

View File

@@ -188,6 +188,20 @@ module.exports = function (Categories) {
await Categories.updateRecentTidForCid(cid);
};
Categories.onTopicsMoved = async (cids) => {
await Promise.all(cids.map(async (cid) => {
await Promise.all([
Categories.setCategoryField(
cid, 'topic_count', await db.sortedSetCard(`cid:${cid}:tids:lastposttime`)
),
Categories.setCategoryField(
cid, 'post_count', await db.sortedSetCard(`cid:${cid}:pids`)
),
Categories.updateRecentTidForCid(cid),
]);
}));
};
async function filterScheduledTids(tids) {
const scores = await db.sortedSetScores('topics:scheduled', tids);
const now = Date.now();