From 710dfbc3f12689ddaa25d73a5d78df15c83cfa04 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 9 Aug 2021 18:39:33 +0100 Subject: [PATCH 1/2] fix: do not write blocks we already have We had this filter previously, it got removed somewhere. --- packages/ipfs-core/src/block-storage.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/ipfs-core/src/block-storage.js b/packages/ipfs-core/src/block-storage.js index d41a4357d6..90b7b45ce6 100644 --- a/packages/ipfs-core/src/block-storage.js +++ b/packages/ipfs-core/src/block-storage.js @@ -3,6 +3,7 @@ const { BlockstoreAdapter } = require('interface-blockstore') const merge = require('it-merge') const pushable = require('it-pushable') +const filter = require('it-filter') /** * @typedef {import('interface-blockstore').Blockstore} Blockstore @@ -55,6 +56,10 @@ class BlockStorage extends BlockstoreAdapter { * @param {AbortOptions} [options] */ async put (cid, block, options = {}) { + if (await this.has(cid)) { + return + } + if (this.bitswap.isStarted()) { await this.bitswap.put(cid, block, options) } else { @@ -69,10 +74,12 @@ class BlockStorage extends BlockstoreAdapter { * @param {AbortOptions} [options] */ async * putMany (blocks, options = {}) { + const missingBlocks = filter(blocks, async ({ key }) => { return !(await this.has(key)) }) + if (this.bitswap.isStarted()) { - yield * this.bitswap.putMany(blocks, options) + yield * this.bitswap.putMany(missingBlocks, options) } else { - yield * this.child.putMany(blocks, options) + yield * this.child.putMany(missingBlocks, options) } } From 5e1ef1bee53de79cf936f0cd947f923d42c48358 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 9 Aug 2021 18:41:40 +0100 Subject: [PATCH 2/2] chore: add dep --- packages/ipfs-core/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index d2575c3476..1993b5f66c 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -87,6 +87,7 @@ "is-ipfs": "^6.0.1", "it-all": "^1.0.4", "it-drain": "^1.0.3", + "it-filter": "^1.0.2", "it-first": "^1.0.4", "it-last": "^1.0.4", "it-map": "^1.0.4",