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

Commit

Permalink
fix: use dag.getMany to avoid overloading the DHT, when it arrives
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
achingbrain committed Nov 15, 2018
1 parent 370dadd commit f5373ef
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,26 @@ function getChildren (dag, offset, end) {
}

return pull(
pull.values(filteredLinks),
paramap((child, cb) => {
dag.get(child.link.cid, (error, result) => cb(error, {
start: child.start,
end: child.end,
node: result && result.value,
size: child.size
}))
})
pull.once(filteredLinks),
paramap((children, cb) => {
dag.getMany(children.map(child => child.link.cid), (error, results) => {
if (error) {
return cb(error)
}

cb(null, results.map((result, index) => {
const child = children[index]

return {
start: child.start,
end: child.end,
node: result,
size: child.size
}
}))
})
}),
pull.flatten()
)
}
}
Expand Down

0 comments on commit f5373ef

Please sign in to comment.