Commit 090bf568 authored by Kevin Atkinson's avatar Kevin Atkinson

Refactor EnumerateChildren to avoid need for bestEffort parameter.

License: MIT
Signed-off-by: default avatarKevin Atkinson <k@kevina.org>
parent c9dcb025
...@@ -383,17 +383,16 @@ func (t *Batch) Commit() error { ...@@ -383,17 +383,16 @@ func (t *Batch) Commit() error {
// EnumerateChildren will walk the dag below the given root node and add all // EnumerateChildren will walk the dag below the given root node and add all
// unseen children to the passed in set. // unseen children to the passed in set.
// TODO: parallelize to avoid disk latency perf hits? // TODO: parallelize to avoid disk latency perf hits?
func EnumerateChildren(ctx context.Context, ds LinkService, root *cid.Cid, visit func(*cid.Cid) bool, bestEffort bool) error { type GetLinks func(context.Context, *cid.Cid) ([]*node.Link, error)
links, err := ds.GetLinks(ctx, root) func EnumerateChildren(ctx context.Context, getLinks GetLinks, root *cid.Cid, visit func(*cid.Cid) bool) error {
if bestEffort && err == ErrNotFound { links, err := getLinks(ctx, root)
return nil if err != nil {
} else if err != nil {
return err return err
} }
for _, lnk := range links { for _, lnk := range links {
c := lnk.Cid c := lnk.Cid
if visit(c) { if visit(c) {
err = EnumerateChildren(ctx, ds, c, visit, bestEffort) err = EnumerateChildren(ctx, getLinks, c, visit)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -249,7 +249,7 @@ func TestFetchGraph(t *testing.T) { ...@@ -249,7 +249,7 @@ func TestFetchGraph(t *testing.T) {
offline_ds := NewDAGService(bs) offline_ds := NewDAGService(bs)
err = EnumerateChildren(context.Background(), offline_ds, root.Cid(), func(_ *cid.Cid) bool { return true }, false) err = EnumerateChildren(context.Background(), offline_ds.GetLinks, root.Cid(), func(_ *cid.Cid) bool { return true })
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -266,7 +266,7 @@ func TestEnumerateChildren(t *testing.T) { ...@@ -266,7 +266,7 @@ func TestEnumerateChildren(t *testing.T) {
} }
set := cid.NewSet() set := cid.NewSet()
err = EnumerateChildren(context.Background(), ds, root.Cid(), set.Visit, false) err = EnumerateChildren(context.Background(), ds.GetLinks, root.Cid(), set.Visit)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(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