Skip to content

Commit

Permalink
Ref #870: better bulk insert for IDB loadDump() (#871)
Browse files Browse the repository at this point in the history
* Ref #870: better bulk insert for IDB loadDump()

* Add comment
  • Loading branch information
leplatrem authored Nov 2, 2018
1 parent cf47bcd commit aacf46f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/adapters/IDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,19 @@ export default class IDB extends BaseAdapter {
async loadDump(records) {
try {
await this.execute(transaction => {
records.forEach(record => transaction.update(record));
// Since the put operations are asynchronous, we chain
// them together. The last one will be waited for the
// `transaction.oncomplete` callback.
let i = 0;
putNext();

function putNext() {
if (i == records.length) {
return;
}
transaction.update(records[i]).onsuccess = putNext;
++i;
}
});
const previousLastModified = await this.getLastModified();
const lastModified = Math.max(
Expand Down Expand Up @@ -567,7 +579,7 @@ function transactionProxy(adapter, store, preloaded = []) {
},

update(record) {
store.put({ ...record, _cid });
return store.put({ ...record, _cid });
},

delete(id) {
Expand Down

0 comments on commit aacf46f

Please sign in to comment.