From 1d11e6a37dcbb220d24b04b07176e5bb22b4cbe7 Mon Sep 17 00:00:00 2001 From: "Artur M. Wolff" Date: Fri, 5 Aug 2022 09:21:30 +0200 Subject: [PATCH] miniogw: make ListObjects/V2 aware of easier cases This change changes listObjectsExhaustive (that ListObjects / ListObjectsV2 is using) to not list too many items if it doesn't have to. Specifically, if the prefix contains forward slashes, it will always try to limit the scope of its listing by listing from the last forward slash in the prefix. Updates storj/customer-issues#184 Change-Id: Iae3fa0bc509cf089404a348bdaa9bae1c127966e --- miniogw/gateway.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/miniogw/gateway.go b/miniogw/gateway.go index 566a3ac..3f8456e 100644 --- a/miniogw/gateway.go +++ b/miniogw/gateway.go @@ -462,13 +462,17 @@ func (layer *gatewayLayer) listObjectsExhaustive( // have to comply with (*uplink.Project).ListObjects' API. var listPrefix string - if strings.HasSuffix(prefix, "/") { - listPrefix = prefix + // There is a good chance we don't need to list the entire bucket if the + // prefix contains forward slashes! If it does, let's list from the last + // one. If the satellite doesn't give us anything after that chopped-off + // prefix, we won't return anything anyway. + if i := strings.LastIndex(prefix, "/"); i != -1 { + listPrefix = prefix[:i] + "/" } list := project.ListObjects(ctx, bucket, &uplink.ListObjectsOptions{ Prefix: listPrefix, - Recursive: delimiter != "/" || (strings.Contains(prefix, "/") && !strings.HasSuffix(prefix, "/")), + Recursive: delimiter != "/", System: true, Custom: layer.compatibilityConfig.IncludeCustomMetadataListing, })