From e9ae9c22ec15e3ae2965eef3c3d1115d15a69c2a Mon Sep 17 00:00:00 2001 From: KillianG Date: Mon, 18 Nov 2024 16:24:54 +0100 Subject: [PATCH] Optimize listing of keys for data deletion Issue: CLDSRV-570 --- lib/api/apiUtils/object/abortMultipartUpload.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/api/apiUtils/object/abortMultipartUpload.js b/lib/api/apiUtils/object/abortMultipartUpload.js index 4926a65733..633c726e72 100644 --- a/lib/api/apiUtils/object/abortMultipartUpload.js +++ b/lib/api/apiUtils/object/abortMultipartUpload.js @@ -120,17 +120,16 @@ function abortMultipartUpload(authInfo, bucketName, objectKey, uploadId, log, } // The locations were sent to metadata as an array // under partLocations. Pull the partLocations. - let locations = storedParts.map(item => item.value.partLocations); + let locations = storedParts.flatMap(item => item.value.partLocations); if (locations.length === 0) { return next(null, mpuBucket, storedParts, destBucket); } - // flatten the array - locations = [].concat(...locations); + + const existingLocations = new Set(locations.map(loc => loc.key)); if (objectMD?.location) { - const objectLocationLeft = objectMD.location.filter(loc => - !locations.some(existingLoc => existingLoc.key === loc.key)); - locations = locations.concat(objectLocationLeft); + const remainingObjectLocations = objectMD.location.filter(loc => !existingLocations.has(loc.key)); + locations = [...locations, ...remainingObjectLocations]; } return async.eachLimit(locations, 5, (loc, cb) => {