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

Commit f479d28

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 1771483 commit f479d28

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/file.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,26 @@ function getChildren (dag, offset, end) {
142142
}
143143

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

0 commit comments

Comments
 (0)