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