You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pouchdb.apache.org by ja...@apache.org on 2026/02/19 14:35:39 UTC
(pouchdb) 02/06: make updateCheckpoint class method and class methods private
This is an automated email from the ASF dual-hosted git repository.
jan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pouchdb.git
commit 392475e498ded1004fadf6efeb149979dd6e9275
Author: ems <em...@gmail.com>
AuthorDate: Thu Jan 22 00:11:02 2026 +0100
make updateCheckpoint class method and class methods private
---
.../node_modules/pouchdb-checkpointer/src/index.js | 130 ++++++++++-----------
1 file changed, 65 insertions(+), 65 deletions(-)
diff --git a/packages/node_modules/pouchdb-checkpointer/src/index.js b/packages/node_modules/pouchdb-checkpointer/src/index.js
index a6df3ba05..e455d814a 100644
--- a/packages/node_modules/pouchdb-checkpointer/src/index.js
+++ b/packages/node_modules/pouchdb-checkpointer/src/index.js
@@ -13,65 +13,6 @@ const REPLICATOR = "pouchdb";
const CHECKPOINT_HISTORY_SIZE = 5;
const LOWEST_SEQ = 0;
-function updateCheckpoint(db, id, checkpoint, session, returnValue) {
- return db.get(id).catch(function (err) {
- if (err.status === 404) {
- if (db.adapter === 'http' || db.adapter === 'https') {
- explainError(
- 404, 'PouchDB is just checking if a remote checkpoint exists.'
- );
- }
- return {
- session_id: session,
- _id: id,
- history: [],
- replicator: REPLICATOR,
- version: CHECKPOINT_VERSION
- };
- }
- throw err;
- }).then(function (doc) {
- if (returnValue.cancelled) {
- 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(function (item) {
- return item.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);
-
- doc.version = CHECKPOINT_VERSION;
- doc.replicator = REPLICATOR;
-
- doc.session_id = session;
- doc.last_seq = checkpoint;
-
- return db.put(doc).catch(function (err) {
- if (err.status === 409) {
- // retry; someone is trying to write a checkpoint simultaneously
- return updateCheckpoint(db, id, checkpoint, session, returnValue);
- }
- throw err;
- });
- });
-}
-
class CheckpointerInternal {
constructor(src, target, id, returnValue, opts = {
writeSourceCheckpoint: true,
@@ -94,24 +35,24 @@ class CheckpointerInternal {
writeCheckpoint(checkpoint, session) {
const self = this;
- return this.updateTarget(checkpoint, session).then(function () {
- return self.updateSource(checkpoint, session);
+ return this._updateTarget(checkpoint, session).then(function () {
+ return self._updateSource(checkpoint, session);
});
}
- updateTarget(checkpoint, session) {
+ _updateTarget(checkpoint, session) {
if (this.opts.writeTargetCheckpoint) {
- return updateCheckpoint(this.target, this.id, checkpoint,
+ return this._updateCheckpoint(this.target, this.id, checkpoint,
session, this.returnValue);
} else {
return Promise.resolve(true);
}
}
- updateSource(checkpoint, session) {
+ _updateSource(checkpoint, session) {
if (this.opts.writeSourceCheckpoint) {
const self = this;
- return updateCheckpoint(this.src, this.id, checkpoint,
+ return this._updateCheckpoint(this.src, this.id, checkpoint,
session, this.returnValue)
.catch(function (err) {
if (isForbiddenError(err)) {
@@ -125,6 +66,65 @@ class CheckpointerInternal {
}
}
+ _updateCheckpoint(db, id, checkpoint, session, returnValue) {
+ return db.get(id).catch(function (err) {
+ if (err.status === 404) {
+ if (db.adapter === 'http' || db.adapter === 'https') {
+ explainError(
+ 404, 'PouchDB is just checking if a remote checkpoint exists.'
+ );
+ }
+ return {
+ session_id: session,
+ _id: id,
+ history: [],
+ replicator: REPLICATOR,
+ version: CHECKPOINT_VERSION
+ };
+ }
+ throw err;
+ }).then(function (doc) {
+ if (returnValue.cancelled) {
+ 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(function (item) {
+ return item.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);
+
+ doc.version = CHECKPOINT_VERSION;
+ doc.replicator = REPLICATOR;
+
+ doc.session_id = session;
+ doc.last_seq = checkpoint;
+
+ return db.put(doc).catch(function (err) {
+ if (err.status === 409) {
+ // retry; someone is trying to write a checkpoint simultaneously
+ return this._updateCheckpoint(db, id, checkpoint, session, returnValue);
+ }
+ throw err;
+ });
+ });
+ }
+
getCheckpoint() {
const self = this;