diff --git a/src/upgrades/1.10.0/view_deleted_privilege.js b/src/upgrades/1.10.0/view_deleted_privilege.js index a483bcf417..3b65f2d5b7 100644 --- a/src/upgrades/1.10.0/view_deleted_privilege.js +++ b/src/upgrades/1.10.0/view_deleted_privilege.js @@ -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) { diff --git a/src/upgrades/1.10.2/fix_category_topic_zsets.js b/src/upgrades/1.10.2/fix_category_topic_zsets.js index 999383feac..83b4d7b27f 100644 --- a/src/upgrades/1.10.2/fix_category_topic_zsets.js +++ b/src/upgrades/1.10.2/fix_category_topic_zsets.js @@ -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); + 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, }); }, };