Skip to content

Commit

Permalink
(pouchdb#5145) - Update checkpoint even when no changes
Browse files Browse the repository at this point in the history
  • Loading branch information
garethbowen committed May 10, 2016
1 parent aca5c4b commit c98bc95
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/replicate/replicate.js
Expand Up @@ -121,11 +121,7 @@ function replicate(src, target, opts, returnValue, result) {
}
currentBatch = undefined;
getChanges();
}).catch(function (err) {
writingCheckpoint = false;
abortReplication('writeCheckpoint completed with error', err);
throw err;
});
}).catch(onCheckpointError);
}

function getDiffs() {
Expand Down Expand Up @@ -294,15 +290,33 @@ function replicate(src, target, opts, returnValue, result) {
if (changes.results.length > 0) {
changesOpts.since = changes.last_seq;
getChanges();
processPendingBatch(true);
} else {
if (continuous) {
changesOpts.live = true;
getChanges();

var complete = function() {
if (continuous) {
changesOpts.live = true;
getChanges();
} else {
changesCompleted = true;
}
processPendingBatch(true);
};

// update the checkpoint so we start from the right seq next time
if (!currentBatch && changes.last_seq > last_seq) {
writingCheckpoint = true;
checkpointer.writeCheckpoint(changes.last_seq,
session).then(function () {
writingCheckpoint = false;
result.last_seq = last_seq = changes.last_seq;
complete();
})
.catch(onCheckpointError);
} else {
changesCompleted = true;
complete();
}
}
processPendingBatch(true);
}


Expand Down
29 changes: 29 additions & 0 deletions tests/integration/test.replication.js
Expand Up @@ -1548,6 +1548,35 @@ adapters.forEach(function (adapters) {
});
});

it('Empty replication updates checkpoint (#5145)',
function (done) {
var db = new PouchDB(dbs.name);
var remote = new PouchDB(dbs.remote);
var docs1 = [ {_id: '0', integer: 0} ];
remote.bulkDocs({ docs: docs1 }, function () {
var filter = function () {
return false;
};
db.replicate.from(remote, {
filter: filter
}, function (err, result) {
result.ok.should.equal(true);
result.docs_written.should.equal(0);
result.docs_read.should.equal(0);
result.last_seq.should.equal(1);
db.replicate.from(remote, {
filter: filter
}, function (err, result) {
result.ok.should.equal(true);
result.docs_written.should.equal(0);
result.docs_read.should.equal(0);
result.last_seq.should.equal(1);
done();
});
});
});
});

it('Replication with deleted doc', function (done) {
var db = new PouchDB(dbs.name);
var remote = new PouchDB(dbs.remote);
Expand Down

0 comments on commit c98bc95

Please sign in to comment.