From fea90e524fc2feb2783e492773a10801907a3ac6 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Wed, 10 Aug 2022 10:39:27 +0900
Subject: [PATCH] Issue #3294299 by phma, alexpott, pooja saraah, mikelutz:
 Regression in functional test performance with a large number of modules

---
 core/lib/Drupal/Core/Update/UpdateRegistry.php | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/core/lib/Drupal/Core/Update/UpdateRegistry.php b/core/lib/Drupal/Core/Update/UpdateRegistry.php
index 212a9c73b24d..d5c8108842fb 100644
--- a/core/lib/Drupal/Core/Update/UpdateRegistry.php
+++ b/core/lib/Drupal/Core/Update/UpdateRegistry.php
@@ -96,7 +96,7 @@ public function __construct($root, $site_path, array $enabled_extensions, KeyVal
    *   A list of post-update functions that have been removed.
    */
   public function getRemovedPostUpdates($extension) {
-    $this->scanExtensionsAndLoadUpdateFiles();
+    $this->scanExtensionsAndLoadUpdateFiles($extension);
     $function = "{$extension}_removed_post_updates";
     if (function_exists($function)) {
       return $function();
@@ -246,7 +246,7 @@ public function registerInvokedUpdates(array $function_names) {
    *   A list of update functions.
    */
   public function getUpdateFunctions($extension_name) {
-    $this->scanExtensionsAndLoadUpdateFiles();
+    $this->scanExtensionsAndLoadUpdateFiles($extension_name);
     $all_functions = $this->getAvailableUpdateFunctions();
 
     return array_filter($all_functions, function ($function_name) use ($extension_name) {
@@ -257,15 +257,24 @@ public function getUpdateFunctions($extension_name) {
 
   /**
    * Scans all module, theme, and profile extensions and load the update files.
+   *
+   * @param string|null $extension
+   *   (optional) Limits the extension update files loaded to the provided
+   *   extension.
    */
-  protected function scanExtensionsAndLoadUpdateFiles() {
+  protected function scanExtensionsAndLoadUpdateFiles(string $extension = NULL) {
     // Scan for extensions.
-    $extension_discovery = new ExtensionDiscovery($this->root, FALSE, [], $this->sitePath);
+    $extension_discovery = new ExtensionDiscovery($this->root, TRUE, [], $this->sitePath);
     $module_extensions = $extension_discovery->scan('module');
     $theme_extensions = $this->includeThemes() ? $extension_discovery->scan('theme') : [];
     $profile_extensions = $extension_discovery->scan('profile');
     $extensions = array_merge($module_extensions, $theme_extensions, $profile_extensions);
 
+    // Limit to a single extension.
+    if ($extension) {
+      $extensions = array_intersect_key($extensions, [$extension => TRUE]);
+    }
+
     $this->loadUpdateFiles($extensions);
   }
 
-- 
GitLab