MCPcopy Index your code
hub / github.com/apache/pouchdb / getCheckpoint

Method getCheckpoint

lib/index.js:9524–9592  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9522 }
9523
9524 getCheckpoint() {
9525 var self = this;
9526
9527 if (!self.opts.writeSourceCheckpoint && !self.opts.writeTargetCheckpoint) {
9528 return Promise.resolve(LOWEST_SEQ);
9529 }
9530
9531 if (self.opts && self.opts.writeSourceCheckpoint && !self.opts.writeTargetCheckpoint) {
9532 return self.src.get(self.id).then(function (sourceDoc) {
9533 return sourceDoc.last_seq || LOWEST_SEQ;
9534 }).catch(function (err) {
9535 /* istanbul ignore if */
9536 if (err.status !== 404) {
9537 throw err;
9538 }
9539 return LOWEST_SEQ;
9540 });
9541 }
9542
9543 return self.target.get(self.id).then(function (targetDoc) {
9544 if (self.opts && self.opts.writeTargetCheckpoint && !self.opts.writeSourceCheckpoint) {
9545 return targetDoc.last_seq || LOWEST_SEQ;
9546 }
9547
9548 return self.src.get(self.id).then(function (sourceDoc) {
9549 // Since we can't migrate an old version doc to a new one
9550 // (no session id), we just go with the lowest seq in this case
9551 /* istanbul ignore if */
9552 if (targetDoc.version !== sourceDoc.version) {
9553 return LOWEST_SEQ;
9554 }
9555
9556 var version;
9557 if (targetDoc.version) {
9558 version = targetDoc.version.toString();
9559 } else {
9560 version = "undefined";
9561 }
9562
9563 if (version in comparisons) {
9564 return comparisons[version](targetDoc, sourceDoc);
9565 }
9566 /* istanbul ignore next */
9567 return LOWEST_SEQ;
9568 }, function (err) {
9569 if (err.status === 404 && targetDoc.last_seq) {
9570 return self.src.put({
9571 _id: self.id,
9572 last_seq: LOWEST_SEQ
9573 }).then(function () {
9574 return LOWEST_SEQ;
9575 }, function (err) {
9576 if (isForbiddenError(err)) {
9577 self.opts.writeSourceCheckpoint = false;
9578 return targetDoc.last_seq;
9579 }
9580 /* istanbul ignore next */
9581 return LOWEST_SEQ;

Callers 1

startChangesFunction · 0.45

Calls 3

isForbiddenErrorFunction · 0.70
getMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected