diff --git a/pkg/catalog/loader/loader.go b/pkg/catalog/loader/loader.go index b1887149d5..44bbcc59b0 100644 --- a/pkg/catalog/loader/loader.go +++ b/pkg/catalog/loader/loader.go @@ -387,6 +387,11 @@ func (store *Store) areTemplatesValid(filteredTemplatePaths map[string]struct{}) func (store *Store) areWorkflowOrTemplatesValid(filteredTemplatePaths map[string]struct{}, isWorkflow bool, load func(templatePath string, tagFilter *templates.TagFilter) (bool, error)) bool { areTemplatesValid := true + var parsedCache *templates.Cache + if parser, ok := store.config.ExecutorOptions.Parser.(*templates.Parser); ok { + parsedCache = parser.Cache() + } + for templatePath := range filteredTemplatePaths { if _, err := load(templatePath, store.tagFilter); err != nil { if isParsingError(store, "Error occurred loading template %s: %s\n", templatePath, err) { @@ -395,13 +400,26 @@ func (store *Store) areWorkflowOrTemplatesValid(filteredTemplatePaths map[string } } - template, err := templates.Parse(templatePath, store.preprocessor, store.config.ExecutorOptions) - if err != nil { - if isParsingError(store, "Error occurred parsing template %s: %s\n", templatePath, err) { - areTemplatesValid = false - continue + var template *templates.Template + var err error + + if parsedCache != nil { + if cachedTemplate, _, cacheErr := parsedCache.Has(templatePath); cacheErr == nil && cachedTemplate != nil { + template = cachedTemplate } - } else if template == nil { + } + + if template == nil { + template, err = templates.Parse(templatePath, store.preprocessor, store.config.ExecutorOptions) + if err != nil { + if isParsingError(store, "Error occurred parsing template %s: %s\n", templatePath, err) { + areTemplatesValid = false + continue + } + } + } + + if template == nil { // NOTE(dwisiswant0): possibly global matchers template. // This could definitely be handled better, for example by returning an // `ErrGlobalMatchersTemplate` during `templates.Parse` and checking it