perf(templater): skip template engine for strings without {{ (#2820)

This commit is contained in:
Roman Dahm
2026-05-01 14:57:16 +02:00
committed by GitHub
parent ecffcc720f
commit 46f5db22c8

View File

@@ -68,6 +68,13 @@ func ReplaceWithExtra[T any](v T, cache *Cache, extra map[string]any) T {
return v return v
} }
// Optimization: skip if string is not a template
if s, ok := any(v).(string); ok {
if !strings.Contains(s, "{{") {
return v
}
}
// Initialize the cache map if it's not already initialized // Initialize the cache map if it's not already initialized
if cache.cacheMap == nil { if cache.cacheMap == nil {
cache.cacheMap = cache.Vars.ToCacheMap() cache.cacheMap = cache.Vars.ToCacheMap()
@@ -82,6 +89,10 @@ func ReplaceWithExtra[T any](v T, cache *Cache, extra map[string]any) T {
// Traverse the value and parse any template variables // Traverse the value and parse any template variables
copy, err := deepcopy.TraverseStringsFunc(v, func(v string) (string, error) { copy, err := deepcopy.TraverseStringsFunc(v, func(v string) (string, error) {
// Optimization: skip if string is not a template
if !strings.Contains(v, "{{") {
return v, nil
}
tpl, err := template.New("").Funcs(templateFuncs).Parse(v) tpl, err := template.New("").Funcs(templateFuncs).Parse(v)
if err != nil { if err != nil {
return v, err return v, err