Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.

Commit 6ac7acb

Browse files
committed
fix: use dag.getMany to avoid overloading the DHT, when it arrives
Fixes ipfs-inactive/js-ipfs-unixfs-engine#216 by using one call to `dag.getMany` for all children of a given node instead of multiple calls to `dag.get`.
1 parent 370dadd commit 6ac7acb

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

Diff for: src/file.js

+22-9
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,28 @@ function getChildren (dag, offset, end) {
139139
}
140140

141141
return pull(
142-
pull.values(filteredLinks),
143-
paramap((child, cb) => {
144-
dag.get(child.link.cid, (error, result) => cb(error, {
145-
start: child.start,
146-
end: child.end,
147-
node: result && result.value,
148-
size: child.size
149-
}))
150-
})
142+
pull.once(filteredLinks),
143+
paramap((children, cb) => {
144+
dag.getMany(children.map(child => child.link.cid), (error, results) => {
145+
if (error) {
146+
return cb(error)
147+
}
148+
149+
results = results.map((result, index) => {
150+
const child = children[index]
151+
152+
return {
153+
start: child.start,
154+
end: child.end,
155+
node: result,
156+
size: child.size
157+
}
158+
})
159+
160+
cb(null, results)
161+
})
162+
}),
163+
pull.flatten()
151164
)
152165
}
153166
}

0 commit comments

Comments
 (0)