From 4d7799e618311f3d283565c77c538e328523dd5c Mon Sep 17 00:00:00 2001 From: Connie Liu Date: Tue, 3 Dec 2024 10:59:05 -0500 Subject: [PATCH] fix duplicate buckets landing page, may rework --- .../src/queries/object-storage/requests.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/manager/src/queries/object-storage/requests.ts b/packages/manager/src/queries/object-storage/requests.ts index 4176f7393c4..b7bf9d17996 100644 --- a/packages/manager/src/queries/object-storage/requests.ts +++ b/packages/manager/src/queries/object-storage/requests.ts @@ -166,8 +166,21 @@ export const getAllBucketsFromEndpoints = async ( return { buckets: [], errors: [] }; } + // Avoid multiple getBucket calls for the same region while also + // keeping some endpoint information in case of an error being + // returned for that region + const uniqueRegions: Set = new Set(); + const filteredEndpoints: ObjectStorageEndpoint[] = []; + + for (const endpoint of endpoints) { + if (!uniqueRegions.has(endpoint.region)) { + filteredEndpoints.push(endpoint); + } + uniqueRegions.add(endpoint.region); + } + const results = await Promise.all( - endpoints.map((endpoint) => + filteredEndpoints.map((endpoint) => getAll((params) => getBucketsInRegion(endpoint.region, params) )() @@ -187,7 +200,7 @@ export const getAllBucketsFromEndpoints = async ( } }); - if (errors.length === endpoints.length) { + if (errors.length === filteredEndpoints.length) { throw new Error('Unable to get Object Storage buckets.'); }