perf: make upgrade script faster

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 48f1e265f4
commit a07509f770

@ -1,24 +1,23 @@
'use strict'; 'use strict';
const async = require('async');
const batch = require('../../batch'); const batch = require('../../batch');
const posts = require('../../posts'); const posts = require('../../posts');
const db = require('../../database');
module.exports = { module.exports = {
name: 'Calculate image sizes of all uploaded images', name: 'Calculate image sizes of all uploaded images',
timestamp: Date.UTC(2019, 2, 16), timestamp: Date.UTC(2019, 2, 16),
method: function (callback) { method: async function () {
const { progress } = this; const { progress } = this;
batch.processSortedSet('posts:pid', (postData, next) => { await batch.processSortedSet('posts:pid', async (postData) => {
async.eachSeries(postData, async (pid) => { const keys = postData.map(p => `post:${p.pid}:uploads`);
const uploads = await posts.uploads.list(pid); const uploads = await db.getSortedSetRange(keys, 0, -1);
await posts.uploads.saveSize(uploads); await posts.uploads.saveSize(uploads);
progress.incr(); progress.incr(postData.length);
}, next);
}, { }, {
batch: 100,
progress: progress, progress: progress,
}, callback); });
}, },
}; };

Loading…
Cancel
Save