Skip to content

Commit 0b63c6f

Browse files
authored
Merge pull request #119 from CrowdStrike/optimise-activation-speed
Optimise activation speed
2 parents 3c38b98 + 079ac84 commit 0b63c6f

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lib/s3.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ module.exports = CoreObject.extend({
8383
params.ContentEncoding = 'br';
8484
}
8585

86-
return this.fetchRevisions(options)
87-
.then(function(revisions) {
88-
var found = revisions.map(function(element) { return element.revision; }).indexOf(options.revisionKey);
89-
if (found >= 0 && !allowOverwrite) {
86+
return this.findRevision(options)
87+
.then(function(found) {
88+
if (found !== undefined && !allowOverwrite) {
9089
return RSVP.reject("REVISION ALREADY UPLOADED! (set `allowOverwrite: true` if you want to support overwriting revisions)");
9190
}
9291
return RSVP.resolve();
@@ -131,9 +130,8 @@ module.exports = CoreObject.extend({
131130
params.ServerSideEncryption = serverSideEncryption;
132131
}
133132

134-
return this.fetchRevisions(options).then(function(revisions) {
135-
var found = revisions.map(function(element) { return element.revision; }).indexOf(options.revisionKey);
136-
if (found >= 0) {
133+
return this.findRevision(options).then(function(found) {
134+
if (found !== undefined) {
137135
return copyObject(params).then(function() {
138136
plugin.log('✔ ' + revisionKey + " => " + indexKey);
139137
});
@@ -143,6 +141,17 @@ module.exports = CoreObject.extend({
143141
});
144142
},
145143

144+
findRevision: function(options) {
145+
var client = this._client;
146+
var listObjects = RSVP.denodeify(client.listObjects.bind(client));
147+
var bucket = options.bucket;
148+
var prefix = options.prefix;
149+
var revisionPrefix = joinUriSegments(prefix, options.filePattern + ":" + options.revisionKey);
150+
151+
return listObjects({ Bucket: bucket, Prefix: revisionPrefix })
152+
.then((response) => response.Contents.find((element) => element.Key === revisionPrefix));
153+
},
154+
146155
fetchRevisions: function(options) {
147156
var client = this._client;
148157
var bucket = options.bucket;

0 commit comments

Comments
 (0)