mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-07 07:10:07 +01:00
perf: #10410, faster upgrade script
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
/* eslint-disable no-await-in-loop */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
@@ -16,30 +14,29 @@ module.exports = {
|
|||||||
const { progress } = this;
|
const { progress } = this;
|
||||||
|
|
||||||
await batch.processSortedSet('users:joindate', async (uids) => {
|
await batch.processSortedSet('users:joindate', async (uids) => {
|
||||||
const keys = uids.map(uid => `uid:${uid}:uploads`);
|
|
||||||
progress.incr(uids.length);
|
progress.incr(uids.length);
|
||||||
|
|
||||||
for (let idx = 0; idx < uids.length; idx++) {
|
await Promise.all(uids.map(async (uid) => {
|
||||||
const key = keys[idx];
|
const key = `uid:${uid}:uploads`;
|
||||||
// Rename the paths within
|
// Rename the paths within
|
||||||
let uploads = await db.getSortedSetRangeWithScores(key, 0, -1);
|
let uploads = await db.getSortedSetRangeWithScores(key, 0, -1);
|
||||||
|
if (uploads.length) {
|
||||||
|
// Don't process those that have already the right format
|
||||||
|
uploads = uploads.filter(upload => upload.value.startsWith('/files/'));
|
||||||
|
|
||||||
// Don't process those that have already the right format
|
await db.sortedSetRemove(key, uploads.map(upload => upload.value));
|
||||||
uploads = uploads.filter(upload => upload.value.startsWith('/files/'));
|
await db.sortedSetAdd(
|
||||||
|
key,
|
||||||
await db.sortedSetRemove(key, uploads.map(upload => upload.value));
|
uploads.map(upload => upload.score),
|
||||||
await db.sortedSetAdd(
|
uploads.map(upload => upload.value.slice(1))
|
||||||
key,
|
);
|
||||||
uploads.map(upload => upload.score),
|
// Add uid to the upload's hash object
|
||||||
uploads.map(upload => upload.value.slice(1))
|
uploads = await db.getSortedSetMembers(key);
|
||||||
);
|
await db.setObjectBulk(uploads.map(relativePath => [`upload:${md5(relativePath)}`, { uid: uids[idx] }]));
|
||||||
|
}
|
||||||
// Add uid to the upload's hash object
|
}));
|
||||||
uploads = await db.getSortedSetMembers(key);
|
|
||||||
await db.setObjectBulk(uploads.map(relativePath => [`upload:${md5(relativePath)}`, { uid: uids[idx] }]));
|
|
||||||
}
|
|
||||||
}, {
|
}, {
|
||||||
batch: 100,
|
batch: 500,
|
||||||
progress: progress,
|
progress: progress,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user