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

@@ -3,6 +3,7 @@ package pipeline
import (
"context"
"fmt"
"sync"
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
@@ -12,7 +13,11 @@ func artifactProducerCache(input RunInput, typed *preparedTypedLane, class contr
if input.Cache == nil || class != contracts.ExecutionClassLLMBacked {
return nil
}
index := source.NewDocumentIndex(doc)
sourceIndex := input.cacheSourceIndex
if sourceIndex == nil {
// Standalone operation construction can also defer indexing until decode.
sourceIndex = sync.OnceValue(func() source.DocumentIndex { return source.NewDocumentIndex(doc) })
}
return &contracts.ProducerCache[any]{
Store: input.Cache,
Encode: typed.codec.encode,
@@ -26,9 +31,12 @@ func artifactProducerCache(input RunInput, typed *preparedTypedLane, class contr
if err != nil {
return nil, err
}
for _, ref := range refs {
if err := index.ValidateRef(ref); err != nil {
return nil, fmt.Errorf("cached artifact source reference: %w", err)
if len(refs) > 0 {
index := sourceIndex()
for _, ref := range refs {
if err := index.ValidateRef(ref); err != nil {
return nil, fmt.Errorf("cached artifact source reference: %w", err)
}
}
}
}