Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions packages/node_modules/pouchdb-checkpointer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,41 +69,41 @@ class CheckpointerInternal {

if (returnValue.cancelled) {
return;
}
// if the checkpoint has not changed, do not update
if (doc.last_seq === checkpoint) {
return;
}
}
// if the checkpoint has not changed, do not update
if (doc.last_seq === checkpoint) {
return;
}

// Filter out current entry for this replication
doc.history = (doc.history || []).filter(item => item.session_id !== session);
// Filter out current entry for this replication
doc.history = (doc.history || []).filter(item => item.session_id !== session);

// Add the latest checkpoint to history
doc.history.unshift({
last_seq: checkpoint,
session_id: session
});
// Add the latest checkpoint to history
doc.history.unshift({
last_seq: checkpoint,
session_id: session
});

// Just take the last pieces in history, to
// avoid really big checkpoint docs.
// see comment on history size above
doc.history = doc.history.slice(0, CHECKPOINT_HISTORY_SIZE);
// Just take the last pieces in history, to
// avoid really big checkpoint docs.
// see comment on history size above
doc.history = doc.history.slice(0, CHECKPOINT_HISTORY_SIZE);

doc.version = CHECKPOINT_VERSION;
doc.replicator = REPLICATOR;
doc.version = CHECKPOINT_VERSION;
doc.replicator = REPLICATOR;

doc.session_id = session;
doc.last_seq = checkpoint;
doc.session_id = session;
doc.last_seq = checkpoint;

try {
return await db.put(doc);
} catch (err) {
if (err.status === 409) {
// retry; someone is trying to write a checkpoint simultaneously
return this._updateCheckpoint(db, id, checkpoint, session, returnValue);
}
throw err;
try {
return await db.put(doc);
} catch (err) {
if (err.status === 409) {
// retry; someone is trying to write a checkpoint simultaneously
return this._updateCheckpoint(db, id, checkpoint, session, returnValue);
}
throw err;
}
}

async _initCheckpointDoc(db, id, session) {
Expand Down Expand Up @@ -152,9 +152,9 @@ class CheckpointerInternal {
targetDoc = await this.target.get(this.id);
} catch (err) {
if (err.status !== 404) {
throw err;
}
return LOWEST_SEQ;
throw err;
}
return LOWEST_SEQ;
}

if (this.opts && this.opts.writeTargetCheckpoint && !this.opts.writeSourceCheckpoint) {
Expand All @@ -164,8 +164,8 @@ class CheckpointerInternal {
try {
const sourceDoc = await this.src.get(this.id);
// Since we can't migrate an old version doc to a new one
// (no session id), we just go with the lowest seq in this case
/* istanbul ignore if */
// (no session id), we just go with the lowest seq in this case
/* istanbul ignore if */
if (targetDoc.version !== sourceDoc.version) {
return LOWEST_SEQ;
}
Expand Down
Loading