Share a lazy source index across cache hits
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user