[BUGFIX] Do not recalculate PIDs for every query in BE search 06/54206/2
authorSusanne Moog <susanne.moog@typo3.com>
Fri, 22 Sep 2017 11:38:24 +0000 (13:38 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 25 Sep 2017 08:56:27 +0000 (10:56 +0200)
The backend search "Show all" link recalculated allowed PIDs for
the current user for all search operations resulting in an
exponentially increasing amount of sql queries depending on the
number of pages in an installation.

As the list of allowed pages for the user does not change during
the request, it is enough to calculate it once.

Change-Id: I9262a5d8425d04cb4ff1e35b2c3cc0ec96b8fa53
Resolves: #82083
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/54206
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Sommer <markus.sommer@typo3.org>
Tested-by: Markus Sommer <markus.sommer@typo3.org>
Reviewed-by: Jan Stockfisch <jan.stockfisch@googlemail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php

index d1c8668..b118d9b 100644 (file)
@@ -20,6 +20,7 @@ use TYPO3\CMS\Backend\Routing\UriBuilder;
 use TYPO3\CMS\Backend\Tree\View\PageTreeView;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
 use TYPO3\CMS\Core\Database\Query\QueryHelper;
@@ -1266,6 +1267,13 @@ class AbstractDatabaseRecordList extends AbstractRecordList
      */
     protected function getSearchableWebmounts($id, $depth, $perms_clause)
     {
+        $runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
+        $cacheIdentifier = md5('pidList_' . $id . '_' . $depth . '_' . $perms_clause);
+        $idList = $runtimeCache->get($cacheIdentifier);
+        if ($idList) {
+            return $idList;
+        }
+
         $backendUser = $this->getBackendUserAuthentication();
         /** @var PageTreeView $tree */
         $tree = GeneralUtility::makeInstance(PageTreeView::class);
@@ -1285,7 +1293,7 @@ class AbstractDatabaseRecordList extends AbstractRecordList
             }
             $idList = array_merge($idList, $tree->ids);
         }
-
+        $runtimeCache->set($cacheIdentifier, $idList);
         return $idList;
     }
 
@@ -1425,8 +1433,8 @@ class AbstractDatabaseRecordList extends AbstractRecordList
         if ($searchLevels === 0) {
             $constraint = $expressionBuilder->eq($tableName . '.pid', (int)$this->id);
         } elseif ($searchLevels > 0) {
-            $allowedMounts = $this->getSearchableWebmounts($this->id, $searchLevels, $this->perms_clause);
-            $constraint = $expressionBuilder->in($tableName . '.pid', array_map('intval', $allowedMounts));
+            $allowedPidList = $this->getSearchableWebmounts($this->id, $searchLevels, $this->perms_clause);
+            $constraint = $expressionBuilder->in($tableName . '.pid', array_map('intval', $allowedPidList));
         }
 
         if (!empty($this->getOverridePageIdList())) {