Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: reduce the number of requests to the server #35

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private URI uriResolve(URI uri, String normalPath) throws URISyntaxException {
@Override
public boolean exists(final String normalPath) {

return isDirectory(normalPath) || isFile(normalPath);
return isFile(normalPath) || isDirectory(normalPath);
}

private ListObjectsV2Result queryPrefix(final String prefix) {
Expand Down Expand Up @@ -396,20 +396,17 @@ public String[] listDirectories(final String normalPath) {

private String[] list(final String normalPath, final boolean onlyDirectories) {

if (!isDirectory(normalPath)) {
throw new N5Exception.N5IOException(normalPath + " is not a valid group");
}

final String pathKey = AmazonS3Utils.getS3Key(normalPath);
final List<String> subGroups = new ArrayList<>();
final String prefix = removeLeadingSlash(addTrailingSlash(pathKey));
final ListObjectsV2Request listObjectsRequest = new ListObjectsV2Request()
.withBucketName(bucketName)
.withPrefix(prefix)
.withDelimiter("/");
ListObjectsV2Result objectsListing;
ListObjectsV2Result objectsListing = s3.listObjectsV2(listObjectsRequest);
if (objectsListing.getKeyCount() <= 0)
throw new N5Exception.N5IOException(normalPath + " is not a valid group");
do {
objectsListing = s3.listObjectsV2(listObjectsRequest);
for (final String commonPrefix : objectsListing.getCommonPrefixes()) {
if (!onlyDirectories || commonPrefix.endsWith("/")) {
final String relativePath = relativize(commonPrefix, prefix);
Expand All @@ -418,6 +415,8 @@ private String[] list(final String normalPath, final boolean onlyDirectories) {
}
}
listObjectsRequest.setContinuationToken(objectsListing.getNextContinuationToken());
if (objectsListing.isTruncated())
objectsListing = s3.listObjectsV2(listObjectsRequest);
} while (objectsListing.isTruncated());
return subGroups.toArray(new String[subGroups.size()]);
}
Expand Down
Loading