|
1 | 1 | package com.scalar.db.storage.objectstorage.cloudstorage; |
2 | 2 |
|
3 | | -import com.google.api.gax.paging.Page; |
4 | 3 | import com.google.cloud.WriteChannel; |
5 | 4 | import com.google.cloud.storage.Blob; |
6 | 5 | import com.google.cloud.storage.BlobId; |
|
18 | 17 | import java.io.IOException; |
19 | 18 | import java.nio.ByteBuffer; |
20 | 19 | import java.nio.charset.StandardCharsets; |
21 | | -import java.util.ArrayList; |
22 | 20 | import java.util.List; |
23 | 21 | import java.util.Optional; |
24 | 22 | import java.util.Set; |
@@ -179,24 +177,22 @@ public void delete(String key, String version) throws ObjectStorageWrapperExcept |
179 | 177 | @Override |
180 | 178 | public void deleteByPrefix(String prefix) throws ObjectStorageWrapperException { |
181 | 179 | try { |
182 | | - Page<Blob> page = storage.list(bucket, Storage.BlobListOption.prefix(prefix)); |
183 | | - while (page != null) { |
184 | | - // Collect BlobIds to delete |
185 | | - List<BlobId> blobIds = new ArrayList<>(); |
186 | | - for (Blob blob : page.getValues()) { |
187 | | - blobIds.add(BlobId.of(bucket, blob.getName())); |
188 | | - } |
189 | | - // Delete objects in batches |
190 | | - for (int i = 0; i < blobIds.size(); i += BATCH_DELETE_SIZE_LIMIT) { |
191 | | - int endIndex = Math.min(i + BATCH_DELETE_SIZE_LIMIT, blobIds.size()); |
192 | | - List<BlobId> batch = blobIds.subList(i, endIndex); |
193 | | - StorageBatch storageBatch = storage.batch(); |
194 | | - for (BlobId blobId : batch) { |
195 | | - storageBatch.delete(blobId); |
196 | | - } |
197 | | - storageBatch.submit(); |
| 180 | + // Collect all blob IDs with the specified prefix |
| 181 | + Iterable<Blob> blobs = |
| 182 | + storage.list(bucket, Storage.BlobListOption.prefix(prefix)).iterateAll(); |
| 183 | + List<BlobId> blobIds = |
| 184 | + StreamSupport.stream(blobs.spliterator(), false) |
| 185 | + .map(blob -> BlobId.of(bucket, blob.getName())) |
| 186 | + .collect(Collectors.toList()); |
| 187 | + // Delete blobs in batches |
| 188 | + for (int i = 0; i < blobIds.size(); i += BATCH_DELETE_SIZE_LIMIT) { |
| 189 | + int endIndex = Math.min(i + BATCH_DELETE_SIZE_LIMIT, blobIds.size()); |
| 190 | + List<BlobId> batch = blobIds.subList(i, endIndex); |
| 191 | + StorageBatch storageBatch = storage.batch(); |
| 192 | + for (BlobId blobId : batch) { |
| 193 | + storageBatch.delete(blobId); |
198 | 194 | } |
199 | | - page = page.getNextPage(); |
| 195 | + storageBatch.submit(); |
200 | 196 | } |
201 | 197 | } catch (Exception e) { |
202 | 198 | throw new ObjectStorageWrapperException( |
|
0 commit comments