Issue #3488179 by phenaproxima, thejimbirch: RecipeConfigurator::getIncludedRecipe() should statically cache recipe objects to avoid performance problems

(cherry picked from commit bc8a19c8f7)
merge-requests/10256/head
Alex Pott 2024-11-19 09:30:00 +00:00
parent d8d9b246fe
commit 01329e9a9f
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
2 changed files with 14 additions and 6 deletions

View File

@ -133,15 +133,13 @@ final class InputConfigurator {
* constraints.
*/
public function collectAll(InputCollectorInterface $collector, array &$processed = []): void {
if (is_array($this->values)) {
throw new \LogicException('Input values cannot be changed once they have been set.');
}
// Don't bother collecting values for a recipe we've already seen.
if (in_array($this->prefix, $processed, TRUE)) {
return;
}
if (is_array($this->values)) {
throw new \LogicException('Input values cannot be changed once they have been set.');
}
// First, collect values for the recipe's dependencies.
/** @var \Drupal\Core\Recipe\Recipe $dependency */
foreach ($this->dependencies->recipes as $dependency) {

View File

@ -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 @@ final class RecipeConfigurator {
$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));