Skip to content

Commit 951e863

Browse files
author
Kelvin Luck
committed
feat: Introduce an optional escape hatch for listAllObjects
There are cases where we might want to page through the list of objects available on S3 but we don't need to keep going once we've found what we are looking for. This commit updates `listAllObjects` to accept an `until` argument - if this is provided then when a new page of results is loaded we check if `some` of them match the `until` - if so we don't bother loading another page. A concrete use-case for this is in #120 - sometimes we just want to find the currently active revision so we only need to loop through the "pages" on S3 until we do.
1 parent 0b63c6f commit 951e863

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/s3.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ module.exports = CoreObject.extend({
174174
});
175175
},
176176

177-
listAllObjects: function(options) {
177+
listAllObjects: function(options, until) {
178178
var client = this._client;
179179
var listObjects = RSVP.denodeify(client.listObjects.bind(client));
180180
var allRevisions = [];
@@ -183,13 +183,14 @@ module.exports = CoreObject.extend({
183183
return listObjects(options).then(function(response) {
184184
[].push.apply(allRevisions, response.Contents);
185185

186-
if (response.IsTruncated) {
187-
var nextMarker = response.Contents[response.Contents.length - 1].Key;
188-
options.Marker = nextMarker;
189-
return listObjectRecursively(options);
190-
} else {
186+
var isComplete = !response.IsTruncated || (until && response.Contents.some(until));
187+
188+
if (isComplete) {
191189
return allRevisions;
192190
}
191+
var nextMarker = response.Contents[response.Contents.length - 1].Key;
192+
options.Marker = nextMarker;
193+
return listObjectRecursively(options);
193194
});
194195
}
195196

0 commit comments

Comments
 (0)