Reuse complete glossary selections across matching stages

This commit is contained in:
2026-11-17 04:26:44 +00:00
parent d26991f0bf
commit 743e64a07a
4 changed files with 39 additions and 14 deletions

View File

@@ -111,20 +111,47 @@ type ProposalResult struct {
Operations []outcomes.Operation `json:"operations,omitempty"`
}
// ResolveModuleRunSpecs derives isolated consumer views from resolved settings.
// GlossarySelectionKey identifies read-only glossary data shared by stages.
// The ordered collection lists and active glossary exemptions affect the data.
type GlossarySelectionKey struct {
context, protected string
exempt bool
}
func GlossarySelection(stage config.Stage) GlossarySelectionKey {
return GlossarySelectionKey{
context: fmt.Sprintf("%q", stage.Glossaries),
protected: fmt.Sprintf("%q", stage.ProtectedTerms),
exempt: stage.Module == modulecatalog.KeyGlossary,
}
}
// ResolveModuleRunSpecs derives consumer views from resolved settings.
// Equal glossary selections share read-only entries and protection terms.
func ResolveModuleRunSpecs(cfg *config.Config) []ModuleRunSpec {
if cfg == nil {
return nil
}
specs := make([]ModuleRunSpec, len(cfg.Pipeline.Stages))
selections := make(map[GlossarySelectionKey]int)
for i, item := range cfg.Pipeline.Stages {
spec := &specs[i]
*spec = ModuleRunSpec{ModuleKey: item.Module, InstanceName: fmt.Sprintf("%s_%d", item.Module, i+1), Index: i, ID: item.ID, Settings: item}
key := GlossarySelection(item)
if prior, ok := selections[key]; ok {
spec.Glossary = specs[prior].Glossary
spec.ProtectedTerms = specs[prior].ProtectedTerms
continue
}
selected := glossary.Select(cfg.GlossaryCollections, item.Glossaries)
protected := glossary.Select(cfg.GlossaryCollections, item.ProtectedTerms)
var excluded []glossary.Entry
if item.Module == modulecatalog.KeyGlossary {
if key.exempt {
excluded = selected
}
specs[i] = ModuleRunSpec{ModuleKey: item.Module, InstanceName: fmt.Sprintf("%s_%d", item.Module, i+1), Index: i, ID: item.ID, Settings: item, Glossary: selected, ProtectedTerms: glossary.Vocabulary(protected, excluded)}
spec.Glossary = selected
spec.ProtectedTerms = glossary.Vocabulary(protected, excluded)
selections[key] = i
}
return specs
}