Skip to content
Open
Changes from 3 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
17 changes: 15 additions & 2 deletions packages/node_modules/pouchdb-adapter-indexeddb/src/bulkDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ 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.

txn.objectStore(DOC_STORE).index('seq').openCursor(null, 'prev').onsuccess = function (evt) {
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.

Would this have the same effect as:

metaStore.get(META_STORE).onsuccess = function (e) {
  metadata.seq = e.target.result.seq;
  ...
}

?

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.

I will have to spend some time analyzing it. It's been too long for me to remember the technical details.

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.

Yes it does. It seems to be a better solution so I've merged and updated the code to match this technique.

if (evt.target.result) {
metadata.seq = evt.target.result.key;
}
resolve();
};
});
}

function updateSeq(i) {
if (i === lastWriteIndex) {
txn.objectStore(META_STORE).put(metadata);
Expand Down Expand Up @@ -405,8 +416,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