diff --git a/.travis.yml b/.travis.yml index d2e373b0..8507920f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ stages: node_js: - '10' + - '12' os: - linux @@ -20,7 +21,6 @@ jobs: include: - stage: check script: - - npx aegir commitlint --travis - npx aegir dep-check - npm run lint diff --git a/README.md b/README.md index f5e46902..c48600eb 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ Get a value at the root of the repo. Put many blocks. -* `block` should be an array of type [Block](https://github.com/ipfs/js-ipfs-block#readme). +* `block` should be an Iterable or AsyncIterable that yields entries of type [Block](https://github.com/ipfs/js-ipfs-block#readme). #### `Promise repo.blocks.get (cid)` diff --git a/src/blockstore.js b/src/blockstore.js index 27fc5415..7d3a4bc0 100644 --- a/src/blockstore.js +++ b/src/blockstore.js @@ -85,26 +85,21 @@ function createBaseStore (store) { /** * Like put, but for more. * - * @param {Array} blocks + * @param {AsyncIterable|Iterable} blocks * @returns {Promise} */ async putMany (blocks) { - const keys = blocks.map((b) => ({ - key: cidToKey(b.cid), - block: b - })) - const batch = store.batch() - await Promise.all( - keys.map(async k => { - if (await store.has(k.key)) { - return - } + for await (const block of blocks) { + const key = cidToKey(block.cid) - batch.put(k.key, k.block.data) - }) - ) + if (await store.has(key)) { + continue + } + + batch.put(key, block.data) + } return batch.commit() },