Commit 17f4c175 authored by Steven Allen's avatar Steven Allen

dedup keys in GetMany

Otherwise, GetMany on the children of a node with duplicate links may fail

License: MIT
Signed-off-by: default avatarSteven Allen <steven@stebalien.com>
parent 5044152b
...@@ -201,7 +201,20 @@ func (n *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld. ...@@ -201,7 +201,20 @@ func (n *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.
return getNodesFromBG(ctx, n.Blocks, keys) return getNodesFromBG(ctx, n.Blocks, keys)
} }
func dedupKeys(keys []*cid.Cid) []*cid.Cid {
set := cid.NewSet()
for _, c := range keys {
set.Add(c)
}
if set.Len() == len(keys) {
return keys
}
return set.Keys()
}
func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []*cid.Cid) <-chan *ipld.NodeOption { func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []*cid.Cid) <-chan *ipld.NodeOption {
keys = dedupKeys(keys)
out := make(chan *ipld.NodeOption, len(keys)) out := make(chan *ipld.NodeOption, len(keys))
blocks := bs.GetBlocks(ctx, keys) blocks := bs.GetBlocks(ctx, keys)
var count int var count int
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment