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 () {
|
method: async function () {
|
||||||
const { progress } = this;
|
const { progress } = this;
|
||||||
const cids = await db.getSortedSetRange('categories:cid', 0, -1);
|
const cids = await db.getSortedSetRange('categories:cid', 0, -1);
|
||||||
|
progress.total = cids.length;
|
||||||
for (const cid of cids) {
|
for (const cid of cids) {
|
||||||
const uids = await db.getSortedSetRange(`group:cid:${cid}:privileges:moderate:members`, 0, -1);
|
const uids = await db.getSortedSetRange(`group:cid:${cid}:privileges:moderate:members`, 0, -1);
|
||||||
for (const uid of uids) {
|
for (const uid of uids) {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/* eslint-disable no-await-in-loop */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const db = require('../../database');
|
const db = require('../../database');
|
||||||
@@ -13,18 +11,24 @@ module.exports = {
|
|||||||
const { progress } = this;
|
const { progress } = this;
|
||||||
|
|
||||||
const topics = require('../../topics');
|
const topics = require('../../topics');
|
||||||
|
progress.total = await db.sortedSetCard('topics:tid');
|
||||||
await batch.processSortedSet('topics:tid', async (tids) => {
|
await batch.processSortedSet('topics:tid', async (tids) => {
|
||||||
for (const tid of tids) {
|
progress.incr(tids.length);
|
||||||
progress.incr();
|
const topicData = await db.getObjectFields(
|
||||||
const topicData = await db.getObjectFields(`topic:${tid}`, ['cid', 'pinned', 'postcount']);
|
tids.map(tid => `topic:${tid}`),
|
||||||
if (parseInt(topicData.pinned, 10) !== 1) {
|
['tid', 'cid', 'pinned', 'postcount'],
|
||||||
|
);
|
||||||
|
const bulkAdd = [];
|
||||||
|
topicData.forEach((topic) => {
|
||||||
|
if (topic && parseInt(topic.pinned, 10) !== 1) {
|
||||||
topicData.postcount = parseInt(topicData.postcount, 10) || 0;
|
topicData.postcount = parseInt(topicData.postcount, 10) || 0;
|
||||||
await db.sortedSetAdd(`cid:${topicData.cid}:tids:posts`, topicData.postcount, tid);
|
bulkAdd.push([`cid:${topicData.cid}:tids:posts`, topicData.postcount, topicData.tid]);
|
||||||
}
|
}
|
||||||
await topics.updateLastPostTimeFromLastPid(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