Skip to content

Commit ddfdaa8

Browse files
committed
Merge pull request #46 from jrowlingson/master
Add maxRecentUploads configuration option
2 parents 1df912d + 25954fc commit ddfdaa8

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ if (context.revisionData.revisionKey && !context.revisionData.activatedRevisionK
148148
}
149149
```
150150

151+
### maxRecentUploads
152+
153+
The maximum number of recent revisions to keep in Redis.
154+
155+
*Default:* `10`
156+
151157
## Activation
152158

153159
As well as uploading a file to Redis, *ember-cli-deploy-redis* has the ability to mark a revision of a deployed file as `current`. This is most commonly used in the [lightning method of deployment][1] whereby an index.html file is pushed to Redis and then served to the user by a web server. The web server could be configured to return any existing revision of the index.html file as requested by a query parameter. However, the revision marked as the currently `active` revision would be returned if no query paramter is present. For more detailed information on this method of deployment please refer to the [ember-cli-deploy-lightning-pack README][1].

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = {
2828
}
2929
},
3030
filePattern: 'index.html',
31+
maxRecentUploads: 10,
3132
distDir: function(context) {
3233
return context.distDir;
3334
},
@@ -61,7 +62,7 @@ module.exports = {
6162
if (!this.pluginConfig.url) {
6263
['host', 'port'].forEach(this.applyDefaultConfigProperty.bind(this));
6364
}
64-
['filePattern', 'distDir', 'keyPrefix', 'activationSuffix', 'revisionKey', 'didDeployMessage', 'redisDeployClient'].forEach(this.applyDefaultConfigProperty.bind(this));
65+
['filePattern', 'distDir', 'keyPrefix', 'activationSuffix', 'revisionKey', 'didDeployMessage', 'redisDeployClient', 'maxRecentUploads'].forEach(this.applyDefaultConfigProperty.bind(this));
6566

6667
this.log('config ok', { verbose: true });
6768
},
@@ -72,6 +73,7 @@ module.exports = {
7273
var distDir = this.readConfig('distDir');
7374
var filePattern = this.readConfig('filePattern');
7475
var keyPrefix = this.readConfig('keyPrefix');
76+
var maxRecentUploads = this.readConfig('maxRecentUploads');
7577
var filePath = path.join(distDir, filePattern);
7678

7779
this.log('Uploading `' + filePath + '`', { verbose: true });

lib/redis.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ module.exports = CoreObject.extend({
2929

3030
this._client = redisLib.createClient(redisOptions);
3131

32-
this._maxNumberOfRecentUploads = 10;
33-
this._allowOverwrite = options.allowOverwrite;
32+
this._maxRecentUploads = options.maxRecentUploads;
33+
this._allowOverwrite = options.allowOverwrite;
3434
},
3535

3636
upload: function(/*keyPrefix, revisionKey, value*/) {
@@ -41,7 +41,7 @@ module.exports = CoreObject.extend({
4141
var revisionKey = args[0] || 'default';
4242
var redisKey = keyPrefix + ':' + revisionKey;
4343

44-
var maxEntries = this._maxNumberOfRecentUploads;
44+
var maxEntries = this._maxRecentUploads;
4545

4646
return Promise.resolve()
4747
.then(this._uploadIfKeyDoesNotExist.bind(this, redisKey, value))

tests/unit/index-nodetest.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ describe('redis plugin', function() {
271271

272272
return previous;
273273
}, []);
274-
assert.equal(messages.length, 9);
274+
assert.equal(messages.length, 10);
275275
});
276276
it('adds default config to the config object', function() {
277277
plugin.configure(context);
@@ -301,7 +301,7 @@ describe('redis plugin', function() {
301301
};
302302
plugin.beforeHook(context);
303303
});
304-
it('warns about missing optional filePattern, distDir, activationSuffix, revisionKey, didDeployMessage, and connection info', function() {
304+
it('warns about missing optional filePattern, distDir, activationSuffix, revisionKey, didDeployMessage, maxNumberOfRecentUploads, and connection info', function() {
305305
plugin.configure(context);
306306
var messages = mockUi.messages.reduce(function(previous, current) {
307307
if (/- Missing config:\s.*, using default:\s/.test(current)) {
@@ -310,7 +310,7 @@ describe('redis plugin', function() {
310310

311311
return previous;
312312
}, []);
313-
assert.equal(messages.length, 8);
313+
assert.equal(messages.length, 9);
314314
});
315315
it('does not add default config to the config object', function() {
316316
plugin.configure(context);
@@ -341,7 +341,7 @@ describe('redis plugin', function() {
341341
};
342342
plugin.beforeHook(context);
343343
});
344-
it('warns about missing optional filePattern, distDir, keyPrefix, revisionKey, didDeployMessage, and connection info', function() {
344+
it('warns about missing optional filePattern, distDir, keyPrefix, revisionKey, didDeployMessage, maxNumberOfRecentUploads, and connection info', function() {
345345
plugin.configure(context);
346346
var messages = mockUi.messages.reduce(function(previous, current) {
347347
if (/- Missing config:\s.*, using default:\s/.test(current)) {
@@ -350,7 +350,7 @@ describe('redis plugin', function() {
350350

351351
return previous;
352352
}, []);
353-
assert.equal(messages.length, 8)
353+
assert.equal(messages.length, 9)
354354
});
355355
it('does not add default config to the config object', function() {
356356
plugin.configure(context);
@@ -381,7 +381,7 @@ describe('redis plugin', function() {
381381
};
382382
plugin.beforeHook(context);
383383
});
384-
it('warns about missing optional filePattern, distDir, keyPrefix, activationSuffix, revisionKey, and didDeployMessage only', function() {
384+
it('warns about missing optional filePattern, distDir, keyPrefix, activationSuffix, revisionKey, maxNumberOfRecentUploads, and didDeployMessage only', function() {
385385
plugin.configure(context);
386386
var messages = mockUi.messages.reduce(function(previous, current) {
387387
if (/- Missing config:\s.*, using default:\s/.test(current)) {
@@ -390,7 +390,7 @@ describe('redis plugin', function() {
390390

391391
return previous;
392392
}, []);
393-
assert.equal(messages.length, 7);
393+
assert.equal(messages.length, 8);
394394
});
395395

396396
it('does not add default config to the config object', function() {

tests/unit/lib/redis-nodetest.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,29 @@ describe('redis', function() {
135135
});
136136
});
137137

138+
it('trims the list of recent uploads if maxRecentUploads exists', function() {
139+
var finalUploads = ['2','3','4','5','key:6'];
140+
141+
var redis = new Redis({ maxRecentUploads: 5 }, new FakeRedis(FakeClient.extend({
142+
get: function(/* key */) {
143+
return Promise.resolve(null);
144+
},
145+
zrange: function(listKey, startIndex, stopIndex) {
146+
var end = this.recentRevisions.length - (Math.abs(stopIndex) - 1);
147+
return this.recentRevisions.slice(0, end);
148+
}
149+
})));
150+
151+
redis._client.recentRevisions = ['1','2','3','4','5'];
152+
153+
var promise = redis.upload('key', '6', 'value');
154+
return assert.isFulfilled(promise)
155+
.then(function() {
156+
assert.equal(redis._client.recentRevisions.length, 5);
157+
assert.deepEqual(redis._client.recentRevisions, finalUploads);
158+
});
159+
});
160+
138161
describe('generating the redis key', function() {
139162
it('will use just the default tag if the tag is not provided', function() {
140163
var redisKey = null;

0 commit comments

Comments
 (0)