diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-01-23 11:27:28 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-01-25 09:27:24 +0100 |
commit | 907ff68bfc345a4ea99197494e44dfe05a56d562 (patch) | |
tree | 477c9d6031a2f6ff8052d84259267ae4c0301159 /lib | |
parent | d51429a47232bbf46a2be832ecfa711f102da802 (diff) | |
download | nextcloud-server-907ff68bfc345a4ea99197494e44dfe05a56d562.tar.gz nextcloud-server-907ff68bfc345a4ea99197494e44dfe05a56d562.zip |
perf(app-framework): Make the app middleware registration lazy
Before this patch, app middlewares were registered on the dispatcher for
every app loaded in a Nextcloud process. With the patch, only
middlewares belonging to the same app of a dispatcher instance are
loaded.
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib')
3 files changed, 14 insertions, 23 deletions
diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php index f5f50b1b775..ff04196fef6 100644 --- a/lib/private/AppFramework/Bootstrap/Coordinator.php +++ b/lib/private/AppFramework/Bootstrap/Coordinator.php @@ -153,7 +153,6 @@ class Coordinator { $this->registrationContext->delegateDashboardPanelRegistrations($this->dashboardManager); $this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher); $this->registrationContext->delegateContainerRegistrations($apps); - $this->registrationContext->delegateMiddlewareRegistrations($apps); } public function getRegistrationContext(): ?RegistrationContext { diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index 04faf330dc3..ac3f42ff2af 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -617,29 +617,10 @@ class RegistrationContext { } /** - * @param App[] $apps + * @return ServiceRegistration<Middleware>[] */ - public function delegateMiddlewareRegistrations(array $apps): void { - while (($middleware = array_shift($this->middlewares)) !== null) { - $appId = $middleware->getAppId(); - if (!isset($apps[$appId])) { - // If we land here something really isn't right. But at least we caught the - // notice that is otherwise emitted for the undefined index - $this->logger->error("App $appId not loaded for the container middleware registration"); - - continue; - } - - try { - $apps[$appId] - ->getContainer() - ->registerMiddleWare($middleware->getService()); - } catch (Throwable $e) { - $this->logger->error("Error during capability registration of $appId: " . $e->getMessage(), [ - 'exception' => $e, - ]); - } - } + public function getMiddlewareRegistrations(): array { + return $this->middlewares; } /** diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 6e0e452bccd..6e7f054a80b 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -315,6 +315,17 @@ class DIContainer extends SimpleContainer implements IAppContainer { $c->get(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) ); + /** @var \OC\AppFramework\Bootstrap\Coordinator $coordinator */ + $coordinator = $c->get(\OC\AppFramework\Bootstrap\Coordinator::class); + $registrationContext = $coordinator->getRegistrationContext(); + if ($registrationContext !== null) { + $appId = $this->getAppName(); + foreach ($registrationContext->getMiddlewareRegistrations() as $middlewareRegistration) { + if ($middlewareRegistration->getAppId() === $appId) { + $dispatcher->registerMiddleware($c->get($middlewareRegistration->getService())); + } + } + } foreach ($this->middleWares as $middleWare) { $dispatcher->registerMiddleware($c->get($middleWare)); } |