MCPcopy
hub / github.com/jetify-com/devbox / FillNarInfoCache

Function FillNarInfoCache

internal/devpkg/narinfo_cache.go:59–93  ·  view source on GitHub ↗

FillNarInfoCache checks the remote binary cache for the narinfo of each package in the list, and caches the result. Callers of IsInBinaryCache may call this function first as a perf-optimization.

(ctx context.Context, packages ...*Package)

Source from the content-addressed store, hash-verified

57// package in the list, and caches the result.
58// Callers of IsInBinaryCache may call this function first as a perf-optimization.
59func FillNarInfoCache(ctx context.Context, packages ...*Package) error {
60 defer debug.FunctionTimer().End()
61
62 eligiblePackages := []*Package{}
63 for _, p := range packages {
64 // IMPORTANT: isEligibleForBinaryCache will call resolve() which is NOT
65 // concurrency safe. Hence, we call it outside of the go-routine.
66 isEligible, err := p.isEligibleForBinaryCache()
67 // If the package is not eligible or there is an error in determining that, then skip it.
68 if isEligible && err == nil {
69 eligiblePackages = append(eligiblePackages, p)
70 }
71 }
72 if len(eligiblePackages) == 0 {
73 return nil
74 }
75
76 group, _ := errgroup.WithContext(ctx)
77 for _, p := range eligiblePackages {
78 pkg := p // copy the loop variable since its used in a closure below
79 outputNames, err := pkg.GetOutputNames()
80 if err != nil {
81 return err
82 }
83
84 for _, outputName := range outputNames {
85 name := outputName
86 group.Go(func() error {
87 _, err := pkg.fetchNarInfoStatusOnce(name)
88 return err
89 })
90 }
91 }
92 return group.Wait()
93}
94
95// areExpectedOutputsInCacheOnce wraps fetchNarInfoStatusOnce and returns true
96// if the expected outputs are in the cache.

Callers 2

newFlakePlanFunction · 0.92

Calls 5

FunctionTimerFunction · 0.92
EndMethod · 0.80
GetOutputNamesMethod · 0.80

Tested by

no test coverage detected