Commit b4033237 authored by Steven Allen's avatar Steven Allen

don't return CIDs on add

The caller can just call `node.Cid()` and returning CIDs from `AddMany` requires
allocation.
parent 6f9115bb
......@@ -71,7 +71,7 @@ func (t *Batch) asyncCommit() {
}
}
go func(b []Node) {
_, err := t.ds.AddMany(b)
err := t.ds.AddMany(b)
t.commitResults <- err
}(t.nodes)
......
......@@ -41,24 +41,20 @@ func (d *testDag) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *NodeOpti
return out
}
func (d *testDag) Add(node Node) (*cid.Cid, error) {
func (d *testDag) Add(node Node) error {
d.mu.Lock()
defer d.mu.Unlock()
c := node.Cid()
d.nodes[c.KeyString()] = node
return c, nil
d.nodes[node.Cid().KeyString()] = node
return nil
}
func (d *testDag) AddMany(nodes []Node) ([]*cid.Cid, error) {
func (d *testDag) AddMany(nodes []Node) error {
d.mu.Lock()
defer d.mu.Unlock()
cids := make([]*cid.Cid, len(nodes))
for i, n := range nodes {
c := n.Cid()
d.nodes[c.KeyString()] = n
cids[i] = c
for _, n := range nodes {
d.nodes[n.Cid().KeyString()] = n
}
return cids, nil
return nil
}
func (d *testDag) Remove(c *cid.Cid) error {
......
......@@ -43,7 +43,7 @@ type DAGService interface {
NodeGetter
// Add adds a node to this DAG.
Add(Node) (*cid.Cid, error)
Add(Node) error
// Remove removes a node from this DAG.
//
......@@ -54,5 +54,5 @@ type DAGService interface {
//
// Consider using NewBatch instead of calling this directly if you need
// to add an unbounded number of nodes to avoid buffering too much.
AddMany([]Node) ([]*cid.Cid, error)
AddMany([]Node) error
}
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