From ee95592cf39f68e625ca898720af71b79f7c2196 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Tue, 19 Nov 2024 09:30:00 +0000 Subject: [PATCH] Issue #3488179 by phenaproxima, thejimbirch: RecipeConfigurator::getIncludedRecipe() should statically cache recipe objects to avoid performance problems (cherry picked from commit bc8a19c8f7a02e72582cee909b80e27cfb2945be) --- core/lib/Drupal/Core/Recipe/RecipeConfigurator.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Core/Recipe/RecipeConfigurator.php b/core/lib/Drupal/Core/Recipe/RecipeConfigurator.php index 8e1402af2d46..e0d8a0f5826e 100644 --- a/core/lib/Drupal/Core/Recipe/RecipeConfigurator.php +++ b/core/lib/Drupal/Core/Recipe/RecipeConfigurator.php @@ -15,6 +15,13 @@ final class RecipeConfigurator { */ public readonly array $recipes; + /** + * A cache of already-loaded recipes, keyed by path. + * + * @var \Drupal\Core\Recipe\Recipe[] + */ + private static array $cache = []; + /** * @param string[] $recipes * A list of recipes for a recipe to apply. The recipes will be applied in @@ -56,8 +63,11 @@ public static function getIncludedRecipe(string $include_path, string $name): Re $path = $include_path . "/$name/recipe.yml"; } + if (array_key_exists($path, static::$cache)) { + return static::$cache[$path]; + } if (file_exists($path)) { - return Recipe::createFromDirectory(dirname($path)); + return static::$cache[$path] = Recipe::createFromDirectory(dirname($path)); } $search_path = dirname($path, 2); throw new UnknownRecipeException($name, $search_path, sprintf("Can not find the %s recipe, search path: %s", $name, $search_path)); -- GitLab