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

fix: use dag.getMany to avoid overloading the DHT, when it arrives #2

Merged
merged 1 commit into from
Nov 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,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