Skip to content

Commit 1d11e6a

Browse files
committed
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
1 parent 72a306c commit 1d11e6a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

miniogw/gateway.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,17 @@ func (layer *gatewayLayer) listObjectsExhaustive(
462462
// have to comply with (*uplink.Project).ListObjects' API.
463463
var listPrefix string
464464

465-
if strings.HasSuffix(prefix, "/") {
466-
listPrefix = prefix
465+
// There is a good chance we don't need to list the entire bucket if the
466+
// prefix contains forward slashes! If it does, let's list from the last
467+
// one. If the satellite doesn't give us anything after that chopped-off
468+
// prefix, we won't return anything anyway.
469+
if i := strings.LastIndex(prefix, "/"); i != -1 {
470+
listPrefix = prefix[:i] + "/"
467471
}
468472

469473
list := project.ListObjects(ctx, bucket, &uplink.ListObjectsOptions{
470474
Prefix: listPrefix,
471-
Recursive: delimiter != "/" || (strings.Contains(prefix, "/") && !strings.HasSuffix(prefix, "/")),
475+
Recursive: delimiter != "/",
472476
System: true,
473477
Custom: layer.compatibilityConfig.IncludeCustomMetadataListing,
474478
})

0 commit comments

Comments
 (0)