Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#8494) - Refreshes seq before indexeddb bulkDocs #8495

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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) {
txn.objectStore(DOC_STORE).index('seq').openCursor(null, 'prev').onsuccess = function (evt) {
Copy link
Member

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
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
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