From ee5936804da74cd8534fcb4d10178207eaa05803 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 15 Apr 2024 10:55:42 +0200 Subject: [PATCH] Do not execute query if no macros found --- .../Templates/HtmlMacroParameterParser.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs b/src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs index 6c7445d2da..8292a2fcf1 100644 --- a/src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs +++ b/src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs @@ -55,9 +55,12 @@ public sealed class HtmlMacroParameterParser : IHtmlMacroParameterParser macroAlias, new Dictionary(macroAttributes, StringComparer.OrdinalIgnoreCase)))); - foreach (UmbracoEntityReference umbracoEntityReference in GetUmbracoEntityReferencesFromMacros(foundMacros)) + if (foundMacros.Count > 0) { - yield return umbracoEntityReference; + foreach (UmbracoEntityReference umbracoEntityReference in GetUmbracoEntityReferencesFromMacros(foundMacros)) + { + yield return umbracoEntityReference; + } } } @@ -82,9 +85,12 @@ public sealed class HtmlMacroParameterParser : IHtmlMacroParameterParser } } - foreach (UmbracoEntityReference umbracoEntityReference in GetUmbracoEntityReferencesFromMacros(foundMacros)) + if (foundMacros.Count > 0) { - yield return umbracoEntityReference; + foreach (UmbracoEntityReference umbracoEntityReference in GetUmbracoEntityReferencesFromMacros(foundMacros)) + { + yield return umbracoEntityReference; + } } } @@ -103,7 +109,9 @@ public sealed class HtmlMacroParameterParser : IHtmlMacroParameterParser var foundMacroUmbracoEntityReferences = new List(); // Get all the macro configs in one hit for these unique macro aliases - this is now cached with a custom cache policy - IEnumerable macroConfigs = macroWithAliasService.GetAll(uniqueMacroAliases.WhereNotNull().ToArray()); + IEnumerable macroConfigs = uniqueMacroAliases.Any() + ? macroWithAliasService.GetAll(uniqueMacroAliases.WhereNotNull().ToArray()) + : Enumerable.Empty(); foreach (Tuple> macro in macros) {