Node.js based forum software built for the modern web
perf: make upgrade script faster
Barış Soner Uşaklıa07509f770f2
diff --git a/src/upgrades/1.12.1/post_upload_sizes.js b/src/upgrades/1.12.1/post_upload_sizes.jsindex 1f91a16a79..37df4e70c8 100644--- a/src/upgrades/1.12.1/post_upload_sizes.js+++ b/src/upgrades/1.12.1/post_upload_sizes.js@@ -1,24 +1,23 @@'use strict';-const async = require('async');-const batch = require('../../batch');const posts = require('../../posts');+const db = require('../../database');module.exports = {name: 'Calculate image sizes of all uploaded images',timestamp: Date.UTC(2019, 2, 16),- method: function (callback) {+ method: async function () {const { progress } = this;- batch.processSortedSet('posts:pid', (postData, next) => {- async.eachSeries(postData, async (pid) => {- const uploads = await posts.uploads.list(pid);- await posts.uploads.saveSize(uploads);- progress.incr();- }, next);+ await batch.processSortedSet('posts:pid', async (postData) => {+ const keys = postData.map(p => `post:${p.pid}:uploads`);+ const uploads = await db.getSortedSetRange(keys, 0, -1);+ await posts.uploads.saveSize(uploads);+ progress.incr(postData.length);}, {+ batch: 100,progress: progress,- }, callback);+ });},};