Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
feat: precompile the matchAll selector
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed Aug 13, 2021
1 parent e91ab79 commit 760b004
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions helpers/traversal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import (
"github.com/ipld/go-ipld-prime/traversal/selector/builder"
)

var matchAllSelector ipld.Node

func init() {
ssb := builder.NewSelectorSpecBuilder(basicnode.Prototype.Any)
matchAllSelector = ssb.ExploreRecursive(selector.RecursionLimitNone(), ssb.ExploreUnion(
ssb.Matcher(),
ssb.ExploreAll(ssb.ExploreRecursiveEdge()),
)).Node()
}

// Block fetches a schemaless node graph corresponding to single block by link.
func Block(ctx context.Context, f fetcher.Fetcher, link ipld.Link) (ipld.Node, error) {
prototype, err := f.PrototypeFromLink(link)
Expand All @@ -28,11 +38,5 @@ func BlockMatching(ctx context.Context, f fetcher.Fetcher, root ipld.Link, match
// BlockAll traverses all nodes in the graph linked by root. The nodes will be untyped and send over the results
// channel.
func BlockAll(ctx context.Context, f fetcher.Fetcher, root ipld.Link, cb fetcher.FetchCallback) error {
ssb := builder.NewSelectorSpecBuilder(basicnode.Prototype.Any)
allSelector := ssb.ExploreRecursive(selector.RecursionLimitNone(), ssb.ExploreUnion(
ssb.Matcher(),
ssb.ExploreAll(ssb.ExploreRecursiveEdge()),
)).Node()

return f.BlockMatchingOfType(ctx, root, allSelector, nil, cb)
return f.BlockMatchingOfType(ctx, root, matchAllSelector, nil, cb)
}

0 comments on commit 760b004

Please sign in to comment.