[TASK] Add cache to getPagesTSconfig() 23/25223/4
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Fri, 8 Nov 2013 16:10:02 +0000 (17:10 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 11 Nov 2013 17:06:39 +0000 (18:06 +0100)
Add a cache also to BackendUtility::getPagesTSconfig() to save parsing
etc. for multiple lookups in various places inside TYPO3.

The core only uses the first parameter, therefore the cache is only
based on the page ID and ignored if other parameters are given.

Change-Id: I63d49c398ed16daa5c2d8ae707d67f934a24a312
Resolves: #53462
Releases: 6.2
Reviewed-on: https://review.typo3.org/25223
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/backend/Classes/Utility/BackendUtility.php

index d66c660..12685e9 100644 (file)
@@ -1128,35 +1128,53 @@ class BackendUtility {
         * @return array Page TSconfig
         * @see \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
         */
-       static public function getPagesTSconfig($id, $rootLine = '', $returnPartArray = 0) {
+       static public function getPagesTSconfig($id, $rootLine = NULL, $returnPartArray = FALSE) {
+               static $pagesTSconfig_cache = array();
+
                $id = intval($id);
-               if (!is_array($rootLine)) {
-                       $rootLine = self::BEgetRootLine($id, '', TRUE);
-               }
-               // Order correctly
-               ksort($rootLine);
-               $TSdataArray = array();
-               // Setting default configuration
-               $TSdataArray['defaultPageTSconfig'] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
-               foreach ($rootLine as $k => $v) {
-                       $TSdataArray['uid_' . $v['uid']] = $v['TSconfig'];
-               }
-               $TSdataArray = TypoScriptParser::checkIncludeLines_array($TSdataArray);
-               if ($returnPartArray) {
-                       return $TSdataArray;
-               }
-               // Parsing the page TS-Config
-               $pageTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray);
-               /* @var $parseObj \TYPO3\CMS\Backend\Configuration\TsConfigParser */
-               $parseObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TsConfigParser');
-               $res = $parseObj->parseTSconfig($pageTS, 'PAGES', $id, $rootLine);
-               if ($res) {
-                       $TSconfig = $res['TSconfig'];
-               }
-               // Get User TSconfig overlay
-               $userTSconfig = $GLOBALS['BE_USER']->userTS['page.'];
-               if (is_array($userTSconfig)) {
-                       $TSconfig = GeneralUtility::array_merge_recursive_overrule($TSconfig, $userTSconfig);
+               if ($returnPartArray === FALSE
+                       && $rootLine === NULL
+                       && isset($pagesTSconfig_cache[$id])
+               ) {
+                       return $pagesTSconfig_cache[$id];
+               } else {
+                       $TSconfig = array();
+                       if (!is_array($rootLine)) {
+                               $useCacheForCurrentPageId = TRUE;
+                               $rootLine = self::BEgetRootLine($id, '', TRUE);
+                       } else {
+                               $useCacheForCurrentPageId = FALSE;
+                       }
+
+                       // Order correctly
+                       ksort($rootLine);
+                       $TSdataArray = array();
+                       // Setting default configuration
+                       $TSdataArray['defaultPageTSconfig'] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
+                       foreach ($rootLine as $k => $v) {
+                               $TSdataArray['uid_' . $v['uid']] = $v['TSconfig'];
+                       }
+                       $TSdataArray = TypoScriptParser::checkIncludeLines_array($TSdataArray);
+                       if ($returnPartArray) {
+                               return $TSdataArray;
+                       }
+                       // Parsing the page TS-Config
+                       $pageTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray);
+                       /* @var $parseObj \TYPO3\CMS\Backend\Configuration\TsConfigParser */
+                       $parseObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TsConfigParser');
+                       $res = $parseObj->parseTSconfig($pageTS, 'PAGES', $id, $rootLine);
+                       if ($res) {
+                               $TSconfig = $res['TSconfig'];
+                       }
+                       // Get User TSconfig overlay
+                       $userTSconfig = $GLOBALS['BE_USER']->userTS['page.'];
+                       if (is_array($userTSconfig)) {
+                               $TSconfig = GeneralUtility::array_merge_recursive_overrule($TSconfig, $userTSconfig);
+                       }
+
+                       if ($useCacheForCurrentPageId) {
+                               $pagesTSconfig_cache[$id] = $TSconfig;
+                       }
                }
                return $TSconfig;
        }