[BUGFIX] Ensure webmounts in list module are calculated only once 05/56805/3
authorBenni Mack <benni@typo3.org>
Wed, 25 Apr 2018 13:46:28 +0000 (15:46 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Thu, 26 Apr 2018 05:41:24 +0000 (07:41 +0200)
When using the backend search the list module is fetching the list of
PIDs to recursively look for every single TCA table.

A runtime cache is added in order to only look up this information once
per request.

Resolves: #84869
Releases: master, 8.7
Change-Id: Iad9af42a5ba88324da1f23fc354847bc96d9331d
Reviewed-on: https://review.typo3.org/56805
Reviewed-by: Stephan GroƟberndt <stephan.grossberndt@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Daniel Gorges <daniel.gorges@b13.de>
Tested-by: Daniel Gorges <daniel.gorges@b13.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

index 247e69d..c102581 100644 (file)
@@ -24,6 +24,7 @@ use TYPO3\CMS\Backend\Template\ModuleTemplate;
 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\Compatibility\PublicPropertyDeprecationTrait;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
@@ -3961,24 +3962,31 @@ class DatabaseRecordList
      */
     protected function getSearchableWebmounts($id, $depth, $perms_clause)
     {
-        $backendUser = $this->getBackendUserAuthentication();
-        /** @var PageTreeView $tree */
-        $tree = GeneralUtility::makeInstance(PageTreeView::class);
-        $tree->init('AND ' . $perms_clause);
-        $tree->makeHTML = 0;
-        $tree->fieldArray = ['uid', 'php_tree_stop'];
-        $idList = [];
-
-        $allowedMounts = !$backendUser->isAdmin() && $id === 0
-            ? $backendUser->returnWebmounts()
-            : [$id];
-
-        foreach ($allowedMounts as $allowedMount) {
-            $idList[] = $allowedMount;
-            if ($depth) {
-                $tree->getTree($allowedMount, $depth, '');
+        $runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
+        $hash = 'webmounts_list' . md5($id . '-' . $depth . '-' . $perms_clause);
+        if ($runtimeCache->has($hash)) {
+            $idList = $runtimeCache->get($hash);
+        } else {
+            $backendUser = $this->getBackendUserAuthentication();
+            /** @var PageTreeView $tree */
+            $tree = GeneralUtility::makeInstance(PageTreeView::class);
+            $tree->init('AND ' . $perms_clause);
+            $tree->makeHTML = 0;
+            $tree->fieldArray = ['uid', 'php_tree_stop'];
+            $idList = [];
+
+            $allowedMounts = !$backendUser->isAdmin() && $id === 0
+                ? $backendUser->returnWebmounts()
+                : [$id];
+
+            foreach ($allowedMounts as $allowedMount) {
+                $idList[] = $allowedMount;
+                if ($depth) {
+                    $tree->getTree($allowedMount, $depth, '');
+                }
+                $idList = array_merge($idList, $tree->ids);
             }
-            $idList = array_merge($idList, $tree->ids);
+            $runtimeCache->set($hash, $idList);
         }
 
         return $idList;