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';
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 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();
}, next);
progress.incr(postData.length);
}, {
batch: 100,
progress: progress,
}, callback);
});
},
};

Loading…
Cancel
Save