mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
perf: update upgrade script to use bulk methods
add missing progress.total
This commit is contained in:
@@ -11,6 +11,7 @@ module.exports = {
|
||||
method: async function () {
|
||||
const { progress } = this;
|
||||
const cids = await db.getSortedSetRange('categories:cid', 0, -1);
|
||||
progress.total = cids.length;
|
||||
for (const cid of cids) {
|
||||
const uids = await db.getSortedSetRange(`group:cid:${cid}:privileges:moderate:members`, 0, -1);
|
||||
for (const uid of uids) {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
@@ -13,18 +11,24 @@ module.exports = {
|
||||
const { progress } = this;
|
||||
|
||||
const topics = require('../../topics');
|
||||
progress.total = await db.sortedSetCard('topics:tid');
|
||||
await batch.processSortedSet('topics:tid', async (tids) => {
|
||||
for (const tid of tids) {
|
||||
progress.incr();
|
||||
const topicData = await db.getObjectFields(`topic:${tid}`, ['cid', 'pinned', 'postcount']);
|
||||
if (parseInt(topicData.pinned, 10) !== 1) {
|
||||
progress.incr(tids.length);
|
||||
const topicData = await db.getObjectFields(
|
||||
tids.map(tid => `topic:${tid}`),
|
||||
['tid', 'cid', 'pinned', 'postcount'],
|
||||
);
|
||||
const bulkAdd = [];
|
||||
topicData.forEach((topic) => {
|
||||
if (topic && parseInt(topic.pinned, 10) !== 1) {
|
||||
topicData.postcount = parseInt(topicData.postcount, 10) || 0;
|
||||
await db.sortedSetAdd(`cid:${topicData.cid}:tids:posts`, topicData.postcount, tid);
|
||||
}
|
||||
await topics.updateLastPostTimeFromLastPid(tid);
|
||||
bulkAdd.push([`cid:${topicData.cid}:tids:posts`, topicData.postcount, topicData.tid]);
|
||||
}
|
||||
});
|
||||
await db.sortedSetAddBulk(bulkAdd);
|
||||
await Promise.all(tids.map(tid => topics.updateLastPostTimeFromLastPid(tid)));
|
||||
}, {
|
||||
progress: progress,
|
||||
batch: 500,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user