Skip to content

Commit

Permalink
Merge pull request #119 from CrowdStrike/optimise-activation-speed
Browse files Browse the repository at this point in the history
Optimise activation speed
  • Loading branch information
lukemelia authored Jul 4, 2022
2 parents 3c38b98 + 079ac84 commit 0b63c6f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ module.exports = CoreObject.extend({
params.ContentEncoding = 'br';
}

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

return this.fetchRevisions(options).then(function(revisions) {
var found = revisions.map(function(element) { return element.revision; }).indexOf(options.revisionKey);
if (found >= 0) {
return this.findRevision(options).then(function(found) {
if (found !== undefined) {
return copyObject(params).then(function() {
plugin.log('✔ ' + revisionKey + " => " + indexKey);
});
Expand All @@ -143,6 +141,17 @@ module.exports = CoreObject.extend({
});
},

findRevision: function(options) {
var client = this._client;
var listObjects = RSVP.denodeify(client.listObjects.bind(client));
var bucket = options.bucket;
var prefix = options.prefix;
var revisionPrefix = joinUriSegments(prefix, options.filePattern + ":" + options.revisionKey);

return listObjects({ Bucket: bucket, Prefix: revisionPrefix })
.then((response) => response.Contents.find((element) => element.Key === revisionPrefix));
},

fetchRevisions: function(options) {
var client = this._client;
var bucket = options.bucket;
Expand Down

0 comments on commit 0b63c6f

Please sign in to comment.