Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 4f532a5

Browse files
authoredAug 10, 2021
fix: do not write blocks we already have (#3801)
We had this filter previously, it got removed somewhere.
1 parent db302d0 commit 4f532a5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
 

‎packages/ipfs-core/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"is-ipfs": "^6.0.1",
8888
"it-all": "^1.0.4",
8989
"it-drain": "^1.0.3",
90+
"it-filter": "^1.0.2",
9091
"it-first": "^1.0.4",
9192
"it-last": "^1.0.4",
9293
"it-map": "^1.0.4",

‎packages/ipfs-core/src/block-storage.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const { BlockstoreAdapter } = require('interface-blockstore')
44
const merge = require('it-merge')
55
const pushable = require('it-pushable')
6+
const filter = require('it-filter')
67

78
/**
89
* @typedef {import('interface-blockstore').Blockstore} Blockstore
@@ -55,6 +56,10 @@ class BlockStorage extends BlockstoreAdapter {
5556
* @param {AbortOptions} [options]
5657
*/
5758
async put (cid, block, options = {}) {
59+
if (await this.has(cid)) {
60+
return
61+
}
62+
5863
if (this.bitswap.isStarted()) {
5964
await this.bitswap.put(cid, block, options)
6065
} else {
@@ -69,10 +74,12 @@ class BlockStorage extends BlockstoreAdapter {
6974
* @param {AbortOptions} [options]
7075
*/
7176
async * putMany (blocks, options = {}) {
77+
const missingBlocks = filter(blocks, async ({ key }) => { return !(await this.has(key)) })
78+
7279
if (this.bitswap.isStarted()) {
73-
yield * this.bitswap.putMany(blocks, options)
80+
yield * this.bitswap.putMany(missingBlocks, options)
7481
} else {
75-
yield * this.child.putMany(blocks, options)
82+
yield * this.child.putMany(missingBlocks, options)
7683
}
7784
}
7885

0 commit comments

Comments
 (0)
This repository has been archived.