Skip to content
Open
Changes from 11 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
18 changes: 16 additions & 2 deletions packages/node_modules/pouchdb-adapter-indexeddb/src/bulkDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,18 @@ export default function (api, req, opts, metadata, dbOpts, idbChanges, callback)
};
}

function refreshMetadataSeq() {
return new Promise(function (resolve) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance of an error in this Promise, requiring a reject() call?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good feedback. Thanks, I've made it more robust.

const metaStore = txn.objectStore(META_LOCAL_STORE);
metaStore.get(META_LOCAL_STORE).onsuccess = function (evt) {
if (evt.target.result) {
metadata.seq = evt.target.result.seq;
}
resolve();
};
});
}

function updateSeq(i) {
if (i === lastWriteIndex) {
txn.objectStore(META_LOCAL_STORE).put(metadata);
Expand Down Expand Up @@ -412,8 +424,10 @@ export default function (api, req, opts, metadata, dbOpts, idbChanges, callback)
callback(null, results);
};

// We would like to use promises here, but idb sucks
fetchExistingDocs(txn, docs);
return refreshMetadataSeq().then(function () {
// We would like to use promises here, but idb sucks
fetchExistingDocs(txn, docs);
});
});
}).catch(function (err) {
callback(err);
Expand Down
Loading