[TASK] Suppress db call for rootline with uid 0 89/58289/7
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 16 Sep 2018 07:38:20 +0000 (09:38 +0200)
committerBenni Mack <benni@typo3.org>
Sun, 16 Sep 2018 17:51:03 +0000 (19:51 +0200)
Page uid 0 has no rootline by definition. The patch adds an
early return to RootlineUtility to suppress some cache->get()
calls. This happens in BE quite often. Additionally, the
SiteFinder does not query RootlineUtility for page uid 0 at
all to save a series of instance creations.

Resolves: #86271
Releases: master
Change-Id: I63c819c6dcd5e5c7a0e226ae16b0ecd6cf391e30
Reviewed-on: https://review.typo3.org/58289
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Site/SiteFinder.php
typo3/sysext/core/Classes/Utility/RootlineUtility.php

index a1ac106..8e5b151 100644 (file)
@@ -106,6 +106,10 @@ class SiteFinder
      */
     public function getSiteByPageId(int $pageId, array $rootLine = null): SiteInterface
     {
+        if ($pageId === 0) {
+            // page uid 0 has no root line. We don't need to ask the root line resolver to know that.
+            $rootLine = [];
+        }
         if (!is_array($rootLine)) {
             try {
                 $rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $pageId)->get();
index bc93a6a..1433974 100644 (file)
@@ -207,6 +207,10 @@ class RootlineUtility
      */
     public function get()
     {
+        if ($this->pageUid === 0) {
+            // pageUid 0 has no root line, return empty array right away
+            return [];
+        }
         if (!isset(static::$localCache[$this->cacheIdentifier])) {
             $entry = static::$cache->get($this->cacheIdentifier);
             if (!$entry) {