Merge pull request #1860 from strongloop/fix/replication-performance
Fix replication performance
This commit is contained in:
commit
1b765922c9
|
@ -175,24 +175,32 @@ module.exports = function(Change) {
|
||||||
if (err) throw new Error(err);
|
if (err) throw new Error(err);
|
||||||
};
|
};
|
||||||
|
|
||||||
async.parallel([
|
change.currentRevision(function(err, rev) {
|
||||||
function getCurrentCheckpoint(next) {
|
|
||||||
change.constructor.getCheckpointModel().current(next);
|
|
||||||
},
|
|
||||||
function getCurrentRevision(next) {
|
|
||||||
change.currentRevision(next);
|
|
||||||
}
|
|
||||||
], doRectify);
|
|
||||||
|
|
||||||
function doRectify(err, results) {
|
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
var checkpoint = results[0];
|
|
||||||
var rev = results[1];
|
|
||||||
|
|
||||||
|
// avoid setting rev and prev to the same value
|
||||||
|
if (currentRev === rev) {
|
||||||
|
change.debug('rev and prev are equal (not updating anything)');
|
||||||
|
return cb(null, change);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME(@bajtos) Allo callers to pass in the checkpoint value
|
||||||
|
// (or even better - a memoized async function to get the cp value)
|
||||||
|
// That will enable `rectifyAll` to cache the checkpoint value
|
||||||
|
change.constructor.getCheckpointModel().current(
|
||||||
|
function(err, checkpoint) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
doRectify(checkpoint, rev);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
function doRectify(checkpoint, rev) {
|
||||||
if (rev) {
|
if (rev) {
|
||||||
// avoid setting rev and prev to the same value
|
|
||||||
if (currentRev === rev) {
|
if (currentRev === rev) {
|
||||||
change.debug('rev and prev are equal (not updating rev)');
|
change.debug('ASSERTION FAILED: Change currentRev==rev ' +
|
||||||
|
'should have been already handled');
|
||||||
|
return cb(null, change);
|
||||||
} else {
|
} else {
|
||||||
change.rev = rev;
|
change.rev = rev;
|
||||||
change.debug('updated revision (was ' + currentRev + ')');
|
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() {
|
describe('change.currentRevision(callback)', function() {
|
||||||
|
|
Loading…
Reference in New Issue