[BUGFIX] Do not recalculate PIDs for every query in BE search 30/53930/4
authorSusanne Moog <susanne.moog@typo3.com>
Wed, 6 Sep 2017 13:21:08 +0000 (15:21 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Fri, 22 Sep 2017 11:35:12 +0000 (13:35 +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/53930
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php

index ca0c96b..a3c4345 100644 (file)
@@ -19,6 +19,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\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
@@ -1277,6 +1278,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);
@@ -1296,7 +1304,7 @@ class AbstractDatabaseRecordList extends AbstractRecordList
             }
             $idList = array_merge($idList, $tree->ids);
         }
-
+        $runtimeCache->set($cacheIdentifier, $idList);
         return $idList;
     }
 
@@ -1441,11 +1449,11 @@ class AbstractDatabaseRecordList extends AbstractRecordList
                 )
             );
         } elseif ($searchLevels > 0) {
-            $allowedMounts = $this->getSearchableWebmounts($this->id, $searchLevels, $this->perms_clause);
+            $allowedPidList = $this->getSearchableWebmounts($this->id, $searchLevels, $this->perms_clause);
             $queryBuilder->andWhere(
                 $queryBuilder->expr()->in(
                     $tableName . '.pid',
-                    $queryBuilder->createNamedParameter($allowedMounts, Connection::PARAM_INT_ARRAY)
+                    $queryBuilder->createNamedParameter($allowedPidList, Connection::PARAM_INT_ARRAY)
                 )
             );
         }