Skip to content

Commit 8759948

Browse files
committed
feat: preload walk using phase state, call preloader once per link
1 parent b422a2c commit 8759948

File tree

4 files changed

+301
-316
lines changed

4 files changed

+301
-316
lines changed

linking/preload/preload.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ package preload
33
import (
44
"context"
55

6-
"github.com/ipld/go-ipld-prime"
76
"github.com/ipld/go-ipld-prime/datamodel"
87
)
98

9+
// Loader is a function that will be called with a link discovered in a preload
10+
// pass of a traversal. A preload pass can be used to collect all links in each
11+
// block prior to traversal of that block, allowing for parallel (background)
12+
// loading of blocks in anticipation of eventual actual load during traversal.
13+
type Loader func(PreloadContext, Link)
14+
1015
// PreloadContext carries information about the current state of a traversal
1116
// where a set of links that may be preloaded were encountered.
1217
type PreloadContext struct {
@@ -26,10 +31,10 @@ type PreloadContext struct {
2631
ParentNode datamodel.Node
2732
}
2833

34+
// Link provides the link encountered during a preload pass, the node it was
35+
// encountered on, and the segment of the path that led to the link.
2936
type Link struct {
3037
Segment datamodel.PathSegment
3138
LinkNode datamodel.Node
32-
Link ipld.Link
39+
Link datamodel.Link
3340
}
34-
35-
type Loader func(PreloadContext, []Link)

traversal/fns.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Config struct {
4949
LinkTargetNodePrototypeChooser LinkTargetNodePrototypeChooser // Chooser for Node implementations to produce during automatic link traversal.
5050
LinkVisitOnlyOnce bool // By default, we visit across links wherever we see them again, even if we've visited them before, because the reason for visiting might be different than it was before since we got to it via a different path. If set to true, track links we've seen before in Progress.SeenLinks and do not visit them again. Note that sufficiently complex selectors may require valid revisiting of some links, so setting this to true can change behavior noticably and should be done with care.
5151
StartAtPath datamodel.Path // If set, causes a traversal to skip forward until passing this path, and only then begins calling visit functions. Block loads will also be skipped wherever possible.
52-
Preloader preload.Loader // use breadth first look aheads to preload links
52+
Preloader preload.Loader // Receives a list of links within each block prior to traversal. This can be used to load blocks in parallel, or even to load blocks in a different order than the traversal would otherwise do.
5353
}
5454

5555
type Budget struct {

0 commit comments

Comments
 (0)