From ed8cbd6ec3db559645e7f0d0648ddf7904280a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 17 Feb 2026 13:01:35 -0500 Subject: [PATCH] refactor: don't create giant array, process in batches of 500 --- src/upgrades/3.8.3/topic-event-ids.js | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/upgrades/3.8.3/topic-event-ids.js b/src/upgrades/3.8.3/topic-event-ids.js index 88368d5de6..ea91c7eca9 100644 --- a/src/upgrades/3.8.3/topic-event-ids.js +++ b/src/upgrades/3.8.3/topic-event-ids.js @@ -2,7 +2,6 @@ 'use strict'; const db = require('../../database'); -const batch = require('../../batch'); module.exports = { name: 'Add id field to all topic events', @@ -12,11 +11,11 @@ module.exports = { let nextId = await db.getObjectField('global', 'nextTopicEventId'); nextId = parseInt(nextId, 10) || 0; + progress.total = Math.max(0, nextId - 1); const ids = []; - for (let i = 1; i < nextId; i++) { - ids.push(i); - } - await batch.processArray(ids, async (eids) => { + const BATCH_SIZE = 500; + + async function processBatch(eids) { const eventData = await db.getObjects(eids.map(eid => `topicEvent:${eid}`)); const bulkSet = []; eventData.forEach((event, idx) => { @@ -28,10 +27,20 @@ module.exports = { } }); await db.setObjectBulk(bulkSet); - progress.incr(eids.length); - }, { - batch: 500, - progress, - }); + } + + for (let i = 1; i < nextId; i++) { + ids.push(i); + if (ids.length >= BATCH_SIZE) { + await processBatch(ids); + progress.incr(ids.length); + ids.length = 0; + } + } + + if (ids.length > 0) { + await processBatch(ids); + progress.incr(ids.length); + } }, };