Node.js based forum software built for the modern web
fix: dupe key errors
Barış Soner Uşaklı770fcd9ea826
diff --git a/src/upgrades/1.19.3/fix_user_uploads_zset.js b/src/upgrades/1.19.3/fix_user_uploads_zset.jsindex 155697bc6d..3b545eea06 100644--- a/src/upgrades/1.19.3/fix_user_uploads_zset.js+++ b/src/upgrades/1.19.3/fix_user_uploads_zset.js@@ -1,3 +1,4 @@+/* eslint-disable no-await-in-loop */'use strict';const crypto = require('crypto');@@ -14,13 +15,11 @@ module.exports = {const { progress } = this;await batch.processSortedSet('users:joindate', async (uids) => {- let keys = uids.map(uid => `uid:${uid}:uploads`);- const exists = await db.exists(keys);- keys = keys.filter((key, idx) => exists[idx]);+ const keys = uids.map(uid => `uid:${uid}:uploads`);+ progress.incr(uids.length);- progress.incr(uids.length - keys.length);-- await Promise.all(keys.map(async (key, idx) => {+ for (let idx = 0; idx < uids.length; idx++) {+ const key = keys[idx];// Rename the paths withinlet uploads = await db.getSortedSetRangeWithScores(key, 0, -1);@@ -37,9 +36,7 @@ module.exports = {// Add uid to the upload's hash objectuploads = await db.getSortedSetMembers(key);await db.setObjectBulk(uploads.map(relativePath => [`upload:${md5(relativePath)}`, { uid: uids[idx] }]));-- progress.incr();- }));+ }}, {batch: 100,progress: progress,diff --git a/src/upgrades/1.19.3/rename_post_upload_hashes.js b/src/upgrades/1.19.3/rename_post_upload_hashes.jsindex 5e702c39ee..017be8cac1 100644--- a/src/upgrades/1.19.3/rename_post_upload_hashes.js+++ b/src/upgrades/1.19.3/rename_post_upload_hashes.js@@ -1,3 +1,5 @@+/* eslint-disable no-await-in-loop */+'use strict';const crypto = require('crypto');@@ -18,9 +20,9 @@ module.exports = {const exists = await db.exists(keys);keys = keys.filter((key, idx) => exists[idx]);- progress.incr(pids.length - keys.length);+ progress.incr(pids.length);- await Promise.all(keys.map(async (key) => {+ for (const key of keys) {// Rename the paths withinlet uploads = await db.getSortedSetRangeWithScores(key, 0, -1);@@ -42,8 +44,7 @@ module.exports = {promises.concat(hashes.map((hash, idx) => db.rename(`upload:${hash}:pids`, `upload:${newHashes[idx]}:pids`)));await Promise.all(promises);- progress.incr();- }));+ }}, {batch: 100,progress: progress,