Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise activation speed #119

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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