From 9205169f002a7fb16aed4875940ea05ae9a91a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 15 Feb 2022 20:51:52 -0500 Subject: [PATCH] fix: one last try --- src/upgrades/1.19.3/rename_post_upload_hashes.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/upgrades/1.19.3/rename_post_upload_hashes.js b/src/upgrades/1.19.3/rename_post_upload_hashes.js index 4986dc78d7..5664243c3f 100644 --- a/src/upgrades/1.19.3/rename_post_upload_hashes.js +++ b/src/upgrades/1.19.3/rename_post_upload_hashes.js @@ -40,10 +40,20 @@ module.exports = { // Rename the object and pids zsets const hashes = uploads.map(upload => md5(upload.value)); const newHashes = uploads.map(upload => md5(`files/${upload.value}`)); - const promises = hashes.map((hash, idx) => db.rename(`upload:${hash}`, `upload:${newHashes[idx]}`)); - promises.concat(hashes.map((hash, idx) => db.rename(`upload:${hash}:pids`, `upload:${newHashes[idx]}:pids`))); - await Promise.all(promises); + // cant use db.rename since `fix_user_uploads_zset.js` upgrade script already creates + // `upload:md5(upload.value) hash, trying to rename to existing key results in dupe error + const oldData = await db.getObjects(hashes.map(hash => `upload:${hash}`)); + const bulkSet = []; + oldData.forEach((data, idx) => { + if (data) { + bulkSet.push([`upload:${newHashes[idx]}`, data]); + } + }); + await db.setObjectBulk(bulkSet); + await db.deleteAll(hashes.map(hash => `upload:${hash}`)); + + await Promise.all(hashes.map((hash, idx) => db.rename(`upload:${hash}:pids`, `upload:${newHashes[idx]}:pids`))); } }, { batch: 100,