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

Commit

Permalink
use simple path selectors with implicit reifier instead of ones keyed…
Browse files Browse the repository at this point in the history
… by name
  • Loading branch information
aschmahmann committed Apr 5, 2023
1 parent e31c48b commit 0580ce2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/graph_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/node/basicnode"
"github.com/ipld/go-ipld-prime/schema"
"github.com/ipld/go-ipld-prime/traversal/selector/builder"
"io"
"net/http"
"runtime"
Expand Down Expand Up @@ -341,7 +342,7 @@ func (api *GraphGateway) tryLoadPathFromBlockstore(ctx context.Context, p gatewa
var lastPath ipld.Path
var lastLink ipld.Link
var requestPath string
pathSel := unixfsnode.UnixFSPathSelector(strings.Join(rem, "/"))
pathSel := pathAllSelector(rem)
if err := fetcherhelpers.BlockMatching(ctx, f, rootCidLink, pathSel, func(result fetcher.FetchResult) error {
lastPath = result.LastBlockPath
lastLink = result.LastBlockLink
Expand Down Expand Up @@ -760,3 +761,21 @@ func (b *blockFetcherExchWrapper) Close() error {
}

var _ exchange.Interface = (*blockFetcherExchWrapper)(nil)

func pathAllSelector(path []string) ipld.Node {
ssb := builder.NewSelectorSpecBuilder(basicnode.Prototype.Any)
return pathSelector(path, ssb, func(p string, s builder.SelectorSpec) builder.SelectorSpec {
return ssb.ExploreUnion(
ssb.Matcher(),
ssb.ExploreFields(func(efsb builder.ExploreFieldsSpecBuilder) { efsb.Insert(p, s) }),
)
})
}

func pathSelector(path []string, ssb builder.SelectorSpecBuilder, reduce func(string, builder.SelectorSpec) builder.SelectorSpec) ipld.Node {
spec := ssb.Matcher()
for i := len(path) - 1; i >= 0; i-- {
spec = reduce(path[i], spec)
}
return spec.Node()
}

0 comments on commit 0580ce2

Please sign in to comment.