Change: correctly rectify no-change
Modify `Change.rectify()` to not make any changes to the Change instance (most notably to not modify the `checkpoint` field) when the tracked model instance was not changed. This should improve the performance of change replication as it reduces the number of unnecessary replications. For example, before this commit, every run of `rectifyAll` would trigger a full sync of all clients, because all change instances would be moved to the current checkpoint.
This commit is contained in:
parent
bfd5059d11
commit
d2aaca7460
|
@ -192,7 +192,8 @@ module.exports = function(Change) {
|
|||
if (rev) {
|
||||
// avoid setting rev and prev to the same value
|
||||
if (currentRev === rev) {
|
||||
change.debug('rev and prev are equal (not updating rev)');
|
||||
change.debug('rev and prev are equal (not updating anything)');
|
||||
return cb(null, change);
|
||||
} else {
|
||||
change.rev = rev;
|
||||
change.debug('updated revision (was ' + currentRev + ')');
|
||||
|
|
|
@ -200,6 +200,23 @@ describe('Change', function() {
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('should not change checkpoint when rev is the same', function(done) {
|
||||
var test = this;
|
||||
var originalCheckpoint = change.checkpoint;
|
||||
var originalRev = change.rev;
|
||||
|
||||
TestModel.checkpoint(function(err, inst) {
|
||||
if (err) return done(err);
|
||||
|
||||
change.rectify(function(err, c) {
|
||||
if (err) return done(err);
|
||||
expect(c.rev, 'rev').to.equal(originalRev); // sanity check
|
||||
expect(c.checkpoint, 'checkpoint').to.equal(originalCheckpoint);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('change.currentRevision(callback)', function() {
|
||||
|
|
Loading…
Reference in New Issue