Commit 82e7692e authored by Lucas Molas's avatar Lucas Molas

dag: deduplicate AddNodeLinkClean into AddNodeLink

`AddNodeLink` used to cache the linked node whereas `AddNodeLinkClean`
did not, however, at some point the former was changed to do the same
thing as the latter (i.e., not cache the linked node). That is, they now
do the same thing so there's no reason to have both.

The name `AddNodeLink` is preserved, even though it used to imply the
cache functionality contrasting with the `Clean` suffix of
`AddNodeLinkClean`, with this function removed the cache connotation
doesn't hold anymore.

License: MIT
Signed-off-by: default avatarLucas Molas <schomatis@gmail.com>
parent d3cca0ac
......@@ -340,7 +340,7 @@ func TestFetchFailure(t *testing.T) {
t.Fatal(err)
}
err = top.AddNodeLinkClean(fmt.Sprintf("AA%d", i), nd)
err = top.AddNodeLink(fmt.Sprintf("AA%d", i), nd)
if err != nil {
t.Fatal(err)
}
......@@ -353,7 +353,7 @@ func TestFetchFailure(t *testing.T) {
t.Fatal(err)
}
err = top.AddNodeLinkClean(fmt.Sprintf("BB%d", i), nd)
err = top.AddNodeLink(fmt.Sprintf("BB%d", i), nd)
if err != nil {
t.Fatal(err)
}
......@@ -597,19 +597,19 @@ func TestEnumerateAsyncFailsNotFound(t *testing.T) {
}
parent := new(ProtoNode)
if err := parent.AddNodeLinkClean("a", a); err != nil {
if err := parent.AddNodeLink("a", a); err != nil {
t.Fatal(err)
}
if err := parent.AddNodeLinkClean("b", b); err != nil {
if err := parent.AddNodeLink("b", b); err != nil {
t.Fatal(err)
}
if err := parent.AddNodeLinkClean("c", c); err != nil {
if err := parent.AddNodeLink("c", c); err != nil {
t.Fatal(err)
}
if err := parent.AddNodeLinkClean("d", d); err != nil {
if err := parent.AddNodeLink("d", d); err != nil {
t.Fatal(err)
}
......@@ -696,7 +696,7 @@ func mkNodeWithChildren(getChild func() *ProtoNode, width int) *ProtoNode {
for i := 0; i < width; i++ {
c := getChild()
if err := cur.AddNodeLinkClean(fmt.Sprint(i), c); err != nil {
if err := cur.AddNodeLink(fmt.Sprint(i), c); err != nil {
panic(err)
}
}
......
......@@ -104,19 +104,6 @@ func (n *ProtoNode) AddNodeLink(name string, that ipld.Node) error {
return nil
}
// AddNodeLinkClean adds a link to another node. without keeping a reference to
// the child node
func (n *ProtoNode) AddNodeLinkClean(name string, that ipld.Node) error {
n.encoded = nil
lnk, err := ipld.MakeLink(that)
if err != nil {
return err
}
n.AddRawLink(name, lnk)
return nil
}
// AddRawLink adds a copy of a link to this node
func (n *ProtoNode) AddRawLink(name string, l *ipld.Link) error {
n.encoded = nil
......
......@@ -75,7 +75,7 @@ func addLink(ctx context.Context, ds ipld.DAGService, root *dag.ProtoNode, child
// ensure no link with that name already exists
_ = root.RemoveNodeLink(childname) // ignore error, only option is ErrNotFound
if err := root.AddNodeLinkClean(childname, childnd); err != nil {
if err := root.AddNodeLink(childname, childnd); err != nil {
return nil, err
}
......@@ -127,7 +127,7 @@ func (e *Editor) insertNodeAtPath(ctx context.Context, root *dag.ProtoNode, path
_ = e.tmp.Remove(ctx, root.Cid())
_ = root.RemoveNodeLink(path[0])
err = root.AddNodeLinkClean(path[0], ndprime)
err = root.AddNodeLink(path[0], ndprime)
if err != nil {
return nil, err
}
......@@ -186,7 +186,7 @@ func (e *Editor) rmLink(ctx context.Context, root *dag.ProtoNode, path []string)
e.tmp.Remove(ctx, root.Cid())
_ = root.RemoveNodeLink(path[0])
err = root.AddNodeLinkClean(path[0], nnode)
err = root.AddNodeLink(path[0], nnode)
if err != nil {
return nil, err
}
......
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