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

@@ -150,21 +150,13 @@ func ProcessingPlan(ctx context.Context, cfg *config.Config, inspectProfile func
}
}
specs := contracts.ResolveModuleRunSpecs(cfg)
type glossarySelection struct {
context, protected string
exempt bool
}
glossaryViews := make(map[glossarySelection]int)
glossaryViews := make(map[contracts.GlossarySelectionKey]int)
for i := range specs {
if err := ctx.Err(); err != nil {
return nil, err
}
spec := &specs[i]
key := glossarySelection{
context: fmt.Sprintf("%q", spec.Settings.Glossaries),
protected: fmt.Sprintf("%q", spec.Settings.ProtectedTerms),
exempt: spec.ModuleKey == modulecatalog.KeyGlossary,
}
key := contracts.GlossarySelection(spec.Settings)
if prior, ok := glossaryViews[key]; ok {
spec.GlossaryVariables = specs[prior].GlossaryVariables
spec.GlossaryView = specs[prior].GlossaryView

View File

@@ -87,7 +87,8 @@ func TestProcessingPlanReusesOnlyMatchingGlossaryViews(t *testing.T) {
if err != nil || len(plan) != 4 || !slices.Equal(inspected, []string{profile}) {
t.Fatalf("plan=%+v inspections=%v error=%v", plan, inspected, err)
}
if plan[0].GlossaryView != plan[1].GlossaryView || plan[0].GlossaryVariables != plan[1].GlossaryVariables ||
if &plan[0].Glossary[0] != &plan[1].Glossary[0] || &plan[0].ProtectedTerms[0] != &plan[1].ProtectedTerms[0] ||
plan[0].GlossaryView != plan[1].GlossaryView || plan[0].GlossaryVariables != plan[1].GlossaryVariables ||
plan[0].GlossaryView == plan[2].GlossaryView || plan[0].GlossaryView == plan[3].GlossaryView ||
plan[2].Glossary[0].ID != "b" || plan[3].GlossaryVariables.ProtectionJSON != "[]" {
t.Fatalf("incorrect glossary reuse or exemptions: %+v", plan)