Share a lazy source index across cache hits

This commit is contained in:
2026-11-22 09:42:06 +00:00
parent 2429f0ae6a
commit 80148ef7e4
4 changed files with 65 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ import (
"path"
"path/filepath"
"strings"
"sync"
"time"
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
@@ -70,6 +71,8 @@ type RunInput struct {
stepID string
references map[referenceTargetKey]contracts.ReferenceSet
referenceReuseEligibility map[referenceTargetKey]bool
// Shared by operation decoders, but built only when a cache hit needs it.
cacheSourceIndex func() source.DocumentIndex
}
type RunOutput struct {
@@ -182,6 +185,9 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
if err := source.ValidateDocument(doc); err != nil {
return failOutput(output), fmt.Errorf("validate source document: %w", err)
}
input.cacheSourceIndex = sync.OnceValue(func() source.DocumentIndex {
return source.NewDocumentIndex(doc)
})
if err := writeDebugTimed(debugRecorder, "source/output.json", debugTimedEnvelope{
Stage: "source",