-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Checklist
- My issue is specific & actionable.
- I am not suggesting a protocol enhancement.
- I have searched on the issue tracker for my issue.
Description
Summary:
dag.get with a path argument should be able to return an array of CIDs, representing all the intermediate IPFS objects it traversed along the path to eventually reach the object it ultimately returns. That would enable much more efficient sequential iteration over complex IPLD data structures.
Use case:
Imagine you are trying to do an in-order traversal over a tree structure encoded in IPLD. From knowing the number of elements in the tree (which could be stored in the root of the tree) and how many children each intermediate node has, you can deterministically calculate the depth of the tree. That would allow you to build a path selector specifying the path from the root of the tree to the left-most leaf node fairly easily, which could then be passed to ipfs.dag.get to get the data from the first leaf node in the tree. But now you want to fetch the second leaf node. You could once again deterministically build a path selector from the root to the second leaf node, but that would have the path once again running from the root, which if the tree is large may involve traversing many intermediate nodes multiple times. Instead, ideally you'd like to already have the CID of the parent node of the first leaf node, and then be able to issue a new query with just the path from that parent node to its second child to get the second leaf node of the overall tree. The problem is that dag.get with the path to the first leaf node will only return the data of the leaf node, not any information about the intermediate nodes it passed through to get there, so you have no way to know the CID of its parent. If the dag.get call returned not just the data from the first leaf node, but also an array of the CIDs it passed through to get there when traversing the path, then you'd be able to intelligently pop CIDs off the back of the resulting list to move back up the tree, and issue new dag queries with new paths to other children nodes as you continue to iterate over the tree structure.