mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
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:
committed by
GitHub
parent
01669fa54e
commit
5607e5bccb
@@ -165,7 +165,6 @@ module.exports = function (Categories) {
|
|||||||
|
|
||||||
// terrible name, should be topics.moveTopicPosts
|
// terrible name, should be topics.moveTopicPosts
|
||||||
Categories.moveRecentReplies = async function (tid, oldCid, cid) {
|
Categories.moveRecentReplies = async function (tid, oldCid, cid) {
|
||||||
await updatePostCount(tid, oldCid, cid);
|
|
||||||
const [pids, topicDeleted] = await Promise.all([
|
const [pids, topicDeleted] = await Promise.all([
|
||||||
topics.getPids(tid),
|
topics.getPids(tid),
|
||||||
topics.getTopicField(tid, 'deleted'),
|
topics.getTopicField(tid, 'deleted'),
|
||||||
@@ -195,16 +194,4 @@ module.exports = function (Categories) {
|
|||||||
]);
|
]);
|
||||||
}, { batch: 500 });
|
}, { batch: 500 });
|
||||||
};
|
};
|
||||||
|
|
||||||
async function updatePostCount(tid, oldCid, newCid) {
|
|
||||||
const postCount = await topics.getTopicField(tid, 'postcount');
|
|
||||||
if (!postCount) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
db.incrObjectFieldBy(`category:${oldCid}`, 'post_count', -postCount),
|
|
||||||
db.incrObjectFieldBy(`category:${newCid}`, 'post_count', postCount),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -188,6 +188,20 @@ module.exports = function (Categories) {
|
|||||||
await Categories.updateRecentTidForCid(cid);
|
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) {
|
async function filterScheduledTids(tids) {
|
||||||
const scores = await db.sortedSetScores('topics:scheduled', tids);
|
const scores = await db.sortedSetScores('topics:scheduled', tids);
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|||||||
@@ -20,13 +20,16 @@ module.exports = function (SocketTopics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const uids = await user.getUidsFromSet('users:online', 0, -1);
|
const uids = await user.getUidsFromSet('users:online', 0, -1);
|
||||||
|
const cids = [parseInt(data.cid, 10)];
|
||||||
await async.eachLimit(data.tids, 10, async (tid) => {
|
await async.eachLimit(data.tids, 10, async (tid) => {
|
||||||
const canMove = await privileges.topics.isAdminOrMod(tid, socket.uid);
|
const canMove = await privileges.topics.isAdminOrMod(tid, socket.uid);
|
||||||
if (!canMove) {
|
if (!canMove) {
|
||||||
throw new Error('[[error:no-privileges]]');
|
throw new Error('[[error:no-privileges]]');
|
||||||
}
|
}
|
||||||
const topicData = await topics.getTopicFields(tid, ['tid', 'cid', 'slug', 'deleted']);
|
const topicData = await topics.getTopicFields(tid, ['tid', 'cid', 'slug', 'deleted']);
|
||||||
|
if (!cids.includes(topicData.cid)) {
|
||||||
|
cids.push(topicData.cid);
|
||||||
|
}
|
||||||
data.uid = socket.uid;
|
data.uid = socket.uid;
|
||||||
await topics.tools.move(tid, data);
|
await topics.tools.move(tid, data);
|
||||||
|
|
||||||
@@ -45,6 +48,8 @@ module.exports = function (SocketTopics) {
|
|||||||
toCid: data.cid,
|
toCid: data.cid,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await categories.onTopicsMoved(cids);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -62,6 +67,7 @@ module.exports = function (SocketTopics) {
|
|||||||
await async.eachLimit(tids, 50, async (tid) => {
|
await async.eachLimit(tids, 50, async (tid) => {
|
||||||
await topics.tools.move(tid, data);
|
await topics.tools.move(tid, data);
|
||||||
});
|
});
|
||||||
|
await categories.onTopicsMoved([data.currentCid, data.cid]);
|
||||||
await events.log({
|
await events.log({
|
||||||
type: `topic-move-all`,
|
type: `topic-move-all`,
|
||||||
uid: socket.uid,
|
uid: socket.uid,
|
||||||
|
|||||||
@@ -274,10 +274,6 @@ module.exports = function (Topics) {
|
|||||||
await categories.moveRecentReplies(tid, oldCid, cid);
|
await categories.moveRecentReplies(tid, oldCid, cid);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1),
|
|
||||||
categories.incrementCategoryFieldBy(cid, 'topic_count', 1),
|
|
||||||
categories.updateRecentTidForCid(cid),
|
|
||||||
categories.updateRecentTidForCid(oldCid),
|
|
||||||
Topics.setTopicFields(tid, {
|
Topics.setTopicFields(tid, {
|
||||||
cid: cid,
|
cid: cid,
|
||||||
oldCid: oldCid,
|
oldCid: oldCid,
|
||||||
|
|||||||
Reference in New Issue
Block a user