Skip to content

Commit 8000d88

Browse files
author
Kelvin Luck
committed
feat: Add fetchOnlyRelevantRevisions config option when activating
If you set this option in your S3 config then we will only load enough revisions from S3 to find the currently active version and then we will stop. The assumption here is that the main use-case for `fetchInitialRevisions` is to be able to do some sort of changelog or audit log from another plugin where we would want to know the details of the previously active revision. Since looping over revisions from S3 can be slow when you have too many of them stored (see #120) we provide an option to short circuit that.
1 parent ccfd427 commit 8000d88

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

index.js

+24
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ module.exports = {
116116
},
117117

118118
fetchInitialRevisions: function(context) {
119+
120+
if (this.readConfig('fetchOnlyRelevantRevisions')) {
121+
this.log('fetchInitialRevisions - fetching only enough revisions to find the active revision', { verbose: true });
122+
return this._fetchActiveRevision();
123+
}
124+
119125
return this._list(context)
120126
.then(function(revisions) {
121127
return {
@@ -124,6 +130,24 @@ module.exports = {
124130
});
125131
},
126132

133+
_fetchActiveRevision: function() {
134+
var bucket = this.readConfig('bucket');
135+
var prefix = this.readConfig('prefix');
136+
var filePattern = this.readConfig('filePattern');
137+
138+
var options = {
139+
bucket: bucket,
140+
prefix: prefix,
141+
filePattern: filePattern,
142+
};
143+
144+
var s3 = new this.S3({ plugin: this });
145+
return s3.getActiveRevision(options)
146+
.then((activeRevision) => {
147+
return { initialRevisions: [activeRevision] };
148+
});
149+
},
150+
127151
_list: function(/* context */) {
128152
var bucket = this.readConfig('bucket');
129153
var prefix = this.readConfig('prefix');

0 commit comments

Comments
 (0)