JCLOUDS-1390: Use FULL projection for list blobs

This avoids a per-object call during detailed listings.
This commit is contained in:
Alin Dreghiciu 2018-03-07 20:21:01 +02:00 committed by Andrew Gaul
parent 22cfbb86f2
commit f6d95d0fda
2 changed files with 5 additions and 7 deletions

View File

@ -45,7 +45,6 @@ import org.jclouds.blobstore.options.CreateContainerOptions;
import org.jclouds.blobstore.options.GetOptions; import org.jclouds.blobstore.options.GetOptions;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.options.PutOptions; import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -79,7 +78,6 @@ import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.hash.HashCode; import com.google.common.hash.HashCode;
import com.google.inject.Provider;
public final class GoogleCloudStorageBlobStore extends BaseBlobStore { public final class GoogleCloudStorageBlobStore extends BaseBlobStore {
@ -87,7 +85,6 @@ public final class GoogleCloudStorageBlobStore extends BaseBlobStore {
private final BucketToStorageMetadata bucketToStorageMetadata; private final BucketToStorageMetadata bucketToStorageMetadata;
private final ObjectToBlobMetadata objectToBlobMetadata; private final ObjectToBlobMetadata objectToBlobMetadata;
private final ObjectListToStorageMetadata objectListToStorageMetadata; private final ObjectListToStorageMetadata objectListToStorageMetadata;
private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider;
private final BlobMetadataToObjectTemplate blobMetadataToObjectTemplate; private final BlobMetadataToObjectTemplate blobMetadataToObjectTemplate;
private final BlobStoreListContainerOptionsToListObjectOptions listContainerOptionsToListObjectOptions; private final BlobStoreListContainerOptionsToListObjectOptions listContainerOptionsToListObjectOptions;
private final Supplier<String> projectId; private final Supplier<String> projectId;
@ -97,7 +94,6 @@ public final class GoogleCloudStorageBlobStore extends BaseBlobStore {
@Memoized Supplier<Set<? extends Location>> locations, PayloadSlicer slicer, GoogleCloudStorageApi api, @Memoized Supplier<Set<? extends Location>> locations, PayloadSlicer slicer, GoogleCloudStorageApi api,
BucketToStorageMetadata bucketToStorageMetadata, ObjectToBlobMetadata objectToBlobMetadata, BucketToStorageMetadata bucketToStorageMetadata, ObjectToBlobMetadata objectToBlobMetadata,
ObjectListToStorageMetadata objectListToStorageMetadata, ObjectListToStorageMetadata objectListToStorageMetadata,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
BlobMetadataToObjectTemplate blobMetadataToObjectTemplate, BlobMetadataToObjectTemplate blobMetadataToObjectTemplate,
BlobStoreListContainerOptionsToListObjectOptions listContainerOptionsToListObjectOptions, BlobStoreListContainerOptionsToListObjectOptions listContainerOptionsToListObjectOptions,
@CurrentProject Supplier<String> projectId, @CurrentProject Supplier<String> projectId,
@ -107,7 +103,6 @@ public final class GoogleCloudStorageBlobStore extends BaseBlobStore {
this.bucketToStorageMetadata = bucketToStorageMetadata; this.bucketToStorageMetadata = bucketToStorageMetadata;
this.objectToBlobMetadata = objectToBlobMetadata; this.objectToBlobMetadata = objectToBlobMetadata;
this.objectListToStorageMetadata = objectListToStorageMetadata; this.objectListToStorageMetadata = objectListToStorageMetadata;
this.fetchBlobMetadataProvider = checkNotNull(fetchBlobMetadataProvider, "fetchBlobMetadataProvider");
this.blobMetadataToObjectTemplate = blobMetadataToObjectTemplate; this.blobMetadataToObjectTemplate = blobMetadataToObjectTemplate;
this.listContainerOptionsToListObjectOptions = listContainerOptionsToListObjectOptions; this.listContainerOptionsToListObjectOptions = listContainerOptionsToListObjectOptions;
this.projectId = projectId; this.projectId = projectId;
@ -192,8 +187,7 @@ public final class GoogleCloudStorageBlobStore extends BaseBlobStore {
public PageSet<? extends StorageMetadata> list(String container, ListContainerOptions options) { public PageSet<? extends StorageMetadata> list(String container, ListContainerOptions options) {
ListObjectOptions listOptions = listContainerOptionsToListObjectOptions.apply(options); ListObjectOptions listOptions = listContainerOptionsToListObjectOptions.apply(options);
ListPageWithPrefixes<GoogleCloudStorageObject> gcsList = api.getObjectApi().listObjects(container, listOptions); ListPageWithPrefixes<GoogleCloudStorageObject> gcsList = api.getObjectApi().listObjects(container, listOptions);
PageSet<? extends StorageMetadata> list = objectListToStorageMetadata.apply(gcsList); return objectListToStorageMetadata.apply(gcsList);
return options.isDetailed() ? fetchBlobMetadataProvider.get().setContainerName(container).apply(list) : list;
} }
/** /**

View File

@ -19,6 +19,7 @@ package org.jclouds.googlecloudstorage.blobstore.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.Projection;
import org.jclouds.googlecloudstorage.options.ListObjectOptions; import org.jclouds.googlecloudstorage.options.ListObjectOptions;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -53,6 +54,9 @@ public class BlobStoreListContainerOptionsToListObjectOptions implements
if (from.getMaxResults() != null) { if (from.getMaxResults() != null) {
httpOptions = httpOptions.maxResults(from.getMaxResults()); httpOptions = httpOptions.maxResults(from.getMaxResults());
} }
if (from.isDetailed()) {
httpOptions = httpOptions.projection(Projection.FULL);
}
return httpOptions; return httpOptions;
} }
} }