From 058cb5df19e4a2fb5a2f1f14399bfa4d42044063 Mon Sep 17 00:00:00 2001 From: Danny van Wijk Date: Fri, 29 Nov 2024 14:33:42 +0100 Subject: [PATCH] Prevent duplicate calls for getting node translation --- .../Router/DomainBasedLocaleRouter.php | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Kunstmaan/MultiDomainBundle/Router/DomainBasedLocaleRouter.php b/src/Kunstmaan/MultiDomainBundle/Router/DomainBasedLocaleRouter.php index 08162a0d47..2a8f5db856 100644 --- a/src/Kunstmaan/MultiDomainBundle/Router/DomainBasedLocaleRouter.php +++ b/src/Kunstmaan/MultiDomainBundle/Router/DomainBasedLocaleRouter.php @@ -105,24 +105,25 @@ protected function getRequestLocale() protected function getNodeTranslation($matchResult) { $key = $matchResult['_controller'] . $matchResult['url'] . $matchResult['_locale'] . $matchResult['_route']; - if (!isset($this->cachedNodeTranslations[$key])) { - $rootNode = $this->domainConfiguration->getRootNode(); - - // Lookup node translation - $nodeTranslationRepo = $this->getNodeTranslationRepository(); - - /* @var NodeTranslation $nodeTranslation */ - $nodeTranslation = $nodeTranslationRepo->getNodeTranslationForUrl( - $matchResult['url'], - $matchResult['_locale'], - false, - null, - $rootNode - ); - $this->cachedNodeTranslations[$key] = $nodeTranslation; + if (\array_key_exists($key, $this->cachedNodeTranslations)) { + return $this->cachedNodeTranslations[$key]; } - return $this->cachedNodeTranslations[$key]; + $rootNode = $this->domainConfiguration->getRootNode(); + + // Lookup node translation + $nodeTranslationRepo = $this->getNodeTranslationRepository(); + + /* @var NodeTranslation $nodeTranslation */ + $nodeTranslation = $nodeTranslationRepo->getNodeTranslationForUrl( + $matchResult['url'], + $matchResult['_locale'], + false, + null, + $rootNode + ); + + return $this->cachedNodeTranslations[$key] = $nodeTranslation; } private function isMultiDomainHost(): bool