Do not execute query if no macros found

This commit is contained in:
Bjarke Berg
2024-04-15 10:55:42 +02:00
parent d765e69713
commit ee5936804d

View File

@@ -55,9 +55,12 @@ public sealed class HtmlMacroParameterParser : IHtmlMacroParameterParser
macroAlias,
new Dictionary<string, string>(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<UmbracoEntityReference>();
// Get all the macro configs in one hit for these unique macro aliases - this is now cached with a custom cache policy
IEnumerable<IMacro> macroConfigs = macroWithAliasService.GetAll(uniqueMacroAliases.WhereNotNull().ToArray());
IEnumerable<IMacro> macroConfigs = uniqueMacroAliases.Any()
? macroWithAliasService.GetAll(uniqueMacroAliases.WhereNotNull().ToArray())
: Enumerable.Empty<IMacro>();
foreach (Tuple<string?, Dictionary<string, string>> macro in macros)
{