Commit 40d57b3d authored by Alex Pott's avatar Alex Pott
Browse files

Issue #356399 by dawehner, beejeebus, catch, sidharrell, klausi, nlisgo, Josh...

Issue #356399 by dawehner, beejeebus, catch, sidharrell, klausi, nlisgo, Josh Waihi, Berdir, martin107: Optimize the route rebuilding process to rebuild on write
parent 260f9367
Loading
Loading
Loading
Loading
+4 −10
Changes for core/core.services.yml: 4 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -343,7 +343,7 @@ services:
    arguments: ['@entity.manager', '@string_translation']
  theme_handler:
    class: Drupal\Core\Extension\ThemeHandler
    arguments: ['@app.root', '@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder_indicator']
    arguments: ['@app.root', '@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder']
  entity.manager:
    class: Drupal\Core\Entity\EntityManager
    arguments: ['@container.namespaces', '@module_handler', '@cache.discovery', '@language_manager', '@string_translation', '@class_resolver', '@typed_data_manager', '@entity.definitions.installed', '@event_dispatcher']
@@ -553,7 +553,7 @@ services:
    arguments: ['@current_route_match']
  router.route_provider:
    class: Drupal\Core\Routing\RouteProvider
    arguments: ['@database', '@router.builder', '@state', '@path.current']
    arguments: ['@database', '@state', '@path.current']
    tags:
      - { name: event_subscriber }
      - { name: backend_overridable }
@@ -635,17 +635,11 @@ services:
    arguments: ['@database', '@state']
    tags:
      - { name: backend_overridable }
  router.builder_indicator:
    class: Drupal\Core\Routing\RouteBuilderIndicator
    arguments: ['@state']
  router.builder:
    class: Drupal\Core\Routing\RouteBuilder
    arguments: ['@router.dumper', '@lock', '@event_dispatcher', '@module_handler', '@controller_resolver', '@access_manager.check_provider', '@router.builder_indicator']
  router.rebuild_subscriber:
    class: Drupal\Core\EventSubscriber\RouterRebuildSubscriber
    arguments: ['@router.builder']
    arguments: ['@router.dumper', '@lock', '@event_dispatcher', '@module_handler', '@controller_resolver', '@access_manager.check_provider']
    tags:
      - { name: event_subscriber }
      - { name: needs_destruction }
  menu.rebuild_subscriber:
    class: Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber
    arguments: ['@lock', '@plugin.manager.menu.link']
−5
Changes for core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php: 0 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -19,11 +19,6 @@
 */
class MenuRouterRebuildSubscriber implements EventSubscriberInterface {

  /**
   * @var \Drupal\Core\Routing\RouteBuilderInterface
   */
  protected $routeBuilder;

  /**
   * @var \Drupal\Core\Lock\LockBackendInterface
   */
+4 −4
Changes for core/lib/Drupal/Core/Extension/ModuleInstaller.php: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -220,9 +220,8 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
        // Now install the module's schema if necessary.
        drupal_install_schema($module);

        // Clear plugin manager caches and flag router to rebuild if requested.
        // Clear plugin manager caches.
        \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
        \Drupal::service('router.builder_indicator')->setRebuildNeeded();

        // Set the schema version to the number of the last update provided by
        // the module, or the minimum core schema version.
@@ -296,6 +295,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) {

    // If any modules were newly installed, invoke hook_modules_installed().
    if (!empty($modules_installed)) {
      \Drupal::service('router.builder')->rebuild();
      $this->moduleHandler->invokeAll('modules_installed', array($modules_installed));
    }

@@ -417,9 +417,8 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
      // its statically cached list.
      drupal_static_reset('system_rebuild_module_data');

      // Clear plugin manager caches and flag router to rebuild if requested.
      // Clear plugin manager caches.
      \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
      \Drupal::service('router.builder_indicator')->setRebuildNeeded();

      // Update the kernel to exclude the uninstalled modules.
      $this->updateKernel($module_filenames);
@@ -438,6 +437,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
      $schema_store = \Drupal::keyValue('system.schema');
      $schema_store->delete($module);
    }
    \Drupal::service('router.builder')->rebuild();
    drupal_get_installed_schema_version(NULL, TRUE);

    // Let other modules react.
+11 −11
Changes for core/lib/Drupal/Core/Extension/ThemeHandler.php: 11 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
use Drupal\Core\Config\ConfigInstallerInterface;
use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Config\PreExistingConfigException;
use Drupal\Core\Routing\RouteBuilderIndicatorInterface;
use Drupal\Core\Routing\RouteBuilderInterface;
use Drupal\Core\State\StateInterface;
use Psr\Log\LoggerInterface;

@@ -88,11 +88,11 @@ class ThemeHandler implements ThemeHandlerInterface {
  protected $logger;

  /**
   * The route builder indicator to rebuild the routes if a theme is installed.
   * The route builder to rebuild the routes if a theme is installed.
   *
   * @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface
   * @var \Drupal\Core\Routing\RouteBuilderInterface
   */
  protected $routeBuilderIndicator;
  protected $routeBuilder;

  /**
   * An extension discovery instance.
@@ -145,13 +145,13 @@ class ThemeHandler implements ThemeHandlerInterface {
   *   database.
   * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
   *   The config manager used to uninstall a theme.
   * @param \Drupal\Core\Routing\RouteBuilderIndicatorInterface $route_builder_indicator
   *   (optional) The route builder indicator service to rebuild the routes if a
   *   theme is installed.
   * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
   *   (optional) The route builder service to rebuild the routes if a theme is
   *   installed.
   * @param \Drupal\Core\Extension\ExtensionDiscovery $extension_discovery
   *   (optional) A extension discovery instance (for unit tests).
   */
  public function __construct($root, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser,LoggerInterface $logger, AssetCollectionOptimizerInterface $css_collection_optimizer = NULL, ConfigInstallerInterface $config_installer = NULL, ConfigManagerInterface $config_manager = NULL, RouteBuilderIndicatorInterface $route_builder_indicator = NULL, ExtensionDiscovery $extension_discovery = NULL) {
  public function __construct($root, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser,LoggerInterface $logger, AssetCollectionOptimizerInterface $css_collection_optimizer = NULL, ConfigInstallerInterface $config_installer = NULL, ConfigManagerInterface $config_manager = NULL, RouteBuilderInterface $route_builder = NULL, ExtensionDiscovery $extension_discovery = NULL) {
    $this->root = $root;
    $this->configFactory = $config_factory;
    $this->moduleHandler = $module_handler;
@@ -161,7 +161,7 @@ public function __construct($root, ConfigFactoryInterface $config_factory, Modul
    $this->cssCollectionOptimizer = $css_collection_optimizer;
    $this->configInstaller = $config_installer;
    $this->configManager = $config_manager;
    $this->routeBuilderIndicator = $route_builder_indicator;
    $this->routeBuilder = $route_builder;
    $this->extensionDiscovery = $extension_discovery;
  }

@@ -624,8 +624,8 @@ protected function getExtensionDiscovery() {
   * Resets some other systems like rebuilding the route information or caches.
   */
  protected function resetSystem() {
    if ($this->routeBuilderIndicator) {
      $this->routeBuilderIndicator->setRebuildNeeded();
    if ($this->routeBuilder) {
      $this->routeBuilder->setRebuildNeeded();
    }
    $this->systemListReset();

−3
Changes for core/lib/Drupal/Core/Menu/LocalTaskManager.php: 0 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -201,9 +201,6 @@ public function getLocalTasksForRoute($route_name) {
        $children = $cache->data['children'];
      }
      else {
        // Maybe some code asked to rebuild the routes, so rebuild the router
        // as we rely on having proper existing routes in dynamic local tasks.
        $this->routeBuilder->rebuildIfNeeded();
        $definitions = $this->getDefinitions();
        // We build the hierarchy by finding all tabs that should
        // appear on the current route.
Loading