diff --git a/merkledag/node.go b/merkledag/node.go index e0e282dba..b07d64b5b 100644 --- a/merkledag/node.go +++ b/merkledag/node.go @@ -90,21 +90,6 @@ func (l *Link) GetNode(ctx context.Context, serv DAGService) (*Node, error) { return serv.Get(ctx, key.Key(l.Hash)) } -// GetNodeAndCache return the MDAG Node that the link points to and store a -// pointer to that node along with the link to speed up further retrivals. A -// timeout is to be specified to avoid taking too much time. -func (l *Link) GetNodeAndCache(ctx context.Context, serv DAGService) (*Node, error) { - if l.node == nil { - nd, err := serv.Get(ctx, key.Key(l.Hash)) - if err != nil { - return nil, err - } - l.node = nd - } - - return l.node, nil -} - // AddNodeLink adds a link to another node. func (n *Node) AddNodeLink(name string, that *Node) error { n.encoded = nil diff --git a/path/resolver.go b/path/resolver.go index 4bb11ecf0..3eaf345ff 100644 --- a/path/resolver.go +++ b/path/resolver.go @@ -111,33 +111,20 @@ func (s *Resolver) ResolveLinks(ctx context.Context, ndd *merkledag.Node, names // for each of the path components for _, name := range names { - var nlink *merkledag.Link - // for each of the links in nd, the current object - for _, link := range nd.Links { - if link.Name == name { - nlink = link - break - } - } + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, time.Minute) + defer cancel() - if nlink == nil || len(nlink.Hash) == 0 { + nextnode, err := nd.GetLinkedNode(ctx, s.DAG, name) + if err == merkledag.ErrLinkNotFound { n, _ := nd.Multihash() return result, ErrNoLink{Name: name, Node: n} + } else if err != nil { + return append(result, nextnode), err } - if nlink.GetCachedNode() == nil { - var cancel context.CancelFunc - ctx, cancel = context.WithTimeout(ctx, time.Minute) - defer cancel() - } - - var err error - nd, err = nlink.GetNodeAndCache(ctx, s.DAG) - if err != nil { - return append(result, nd), err - } - - result = append(result, nd) + nd = nextnode + result = append(result, nextnode) } return result, nil }