Skip to content

Instantly share code, notes, and snippets.

@pgebheim
Created August 9, 2019 21:18
Show Gist options
  • Save pgebheim/f400babc45ad27e6efe4d1fc8fb8e856 to your computer and use it in GitHub Desktop.
Save pgebheim/f400babc45ad27e6efe4d1fc8fb8e856 to your computer and use it in GitHub Desktop.
async setHighestSyncBlock(dbName: string, blockNumber: number, syncing: boolean, rollback = false): Promise<PouchDB.UpsertResponse> {
// NOTE: dbName, in this case, is actually the id of the record in the SyncStatus db.
return this.db.upsert(dbName, (document: SyncDocument) => {
// make sure the truly highest block is always being used
document.blockNumber = rollback ? blockNumber : Math.max(blockNumber, document.blockNumber);
document.syncing = syncing;
// db.upsert sets _rev and _id so we don't have to
return document;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment