MCPcopy Create free account
hub / github.com/apache/pouchdb / updateCheckpoint

Function updateCheckpoint

lib/index.js:9416–9469  ·  view source on GitHub ↗
(db, id, checkpoint, session, returnValue)

Source from the content-addressed store, hash-verified

9414var LOWEST_SEQ = 0;
9415
9416function updateCheckpoint(db, id, checkpoint, session, returnValue) {
9417 return db.get(id).catch(function (err) {
9418 if (err.status === 404) {
9419 if (db.adapter === 'http' || db.adapter === 'https') ;
9420 return {
9421 session_id: session,
9422 _id: id,
9423 history: [],
9424 replicator: REPLICATOR,
9425 version: CHECKPOINT_VERSION
9426 };
9427 }
9428 throw err;
9429 }).then(function (doc) {
9430 if (returnValue.cancelled) {
9431 return;
9432 }
9433
9434 // if the checkpoint has not changed, do not update
9435 if (doc.last_seq === checkpoint) {
9436 return;
9437 }
9438
9439 // Filter out current entry for this replication
9440 doc.history = (doc.history || []).filter(function (item) {
9441 return item.session_id !== session;
9442 });
9443
9444 // Add the latest checkpoint to history
9445 doc.history.unshift({
9446 last_seq: checkpoint,
9447 session_id: session
9448 });
9449
9450 // Just take the last pieces in history, to
9451 // avoid really big checkpoint docs.
9452 // see comment on history size above
9453 doc.history = doc.history.slice(0, CHECKPOINT_HISTORY_SIZE);
9454
9455 doc.version = CHECKPOINT_VERSION;
9456 doc.replicator = REPLICATOR;
9457
9458 doc.session_id = session;
9459 doc.last_seq = checkpoint;
9460
9461 return db.put(doc).catch(function (err) {
9462 if (err.status === 409) {
9463 // retry; someone is trying to write a checkpoint simultaneously
9464 return updateCheckpoint(db, id, checkpoint, session, returnValue);
9465 }
9466 throw err;
9467 });
9468 });
9469}
9470
9471class CheckpointerInternal {
9472 constructor(src, target, id, returnValue, opts = {

Callers 2

updateTargetMethod · 0.70
updateSourceMethod · 0.70

Calls 1

getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…