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 {
// EnumerateChildren will walk the dag below the given root node and add all
// unseen children to the passed in set.
// 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 {
links, err := ds.GetLinks(ctx, root)
if bestEffort && err == ErrNotFound {
return nil
} else if err != nil {
type GetLinks func(context.Context, *cid.Cid) ([]*node.Link, error)
func EnumerateChildren(ctx context.Context, getLinks GetLinks, root *cid.Cid, visit func(*cid.Cid) bool) error {
links, err := getLinks(ctx, root)
if err != nil {
return err
}
for _, lnk := range links {
c := lnk.Cid
if visit(c) {
err = EnumerateChildren(ctx, ds, c, visit, bestEffort)
err = EnumerateChildren(ctx, getLinks, c, visit)
if err != nil {
return err
}
......
......@@ -249,7 +249,7 @@ func TestFetchGraph(t *testing.T) {
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 {
t.Fatal(err)
}
......@@ -266,7 +266,7 @@ func TestEnumerateChildren(t *testing.T) {
}
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 {
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