Fix Change.getCheckpointModel() giving new models each call

This was a huge memory leak in our app...
This commit is contained in:
Farid Neshat 2014-12-24 23:40:48 +08:00
parent 906aa8bc07
commit d5d7ecd0bb
2 changed files with 7 additions and 1 deletions

View File

@ -419,7 +419,7 @@ module.exports = function(Change) {
Change.getCheckpointModel = function() {
var checkpointModel = this.Checkpoint;
if (checkpointModel) return checkpointModel;
this.checkpoint = checkpointModel = loopback.Checkpoint.extend('checkpoint');
this.Checkpoint = checkpointModel = loopback.Checkpoint.extend('checkpoint');
assert(this.dataSource, 'Cannot getCheckpointModel(): ' + this.modelName
+ ' is not attached to a dataSource');
checkpointModel.attachTo(this.dataSource);

View File

@ -28,6 +28,12 @@ describe('Change', function() {
});
});
describe('Change.getCheckpointModel()', function() {
it('Shouldnt create two models if called twice', function() {
assert.equal(Change.getCheckpointModel(), Change.getCheckpointModel());
});
});
describe('change.id', function() {
it('should be a hash of the modelName and modelId', function() {
var change = new Change({