perf: update upgrade script to use bulk methods

add missing progress.total
This commit is contained in:
Barış Soner Uşaklı
2025-09-25 11:02:12 -04:00
parent 32d0ee4808
commit 0a2fa45da1
2 changed files with 15 additions and 10 deletions

View File

@@ -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) {

View File

@@ -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,
}); });
}, },
}; };