[BUGFIX] TS is fetched from cache incorrectly sometimes 39/16939/3
authorDmitry Dulepov <dmitry@typo3.org>
Mon, 3 Dec 2012 09:40:25 +0000 (13:40 +0400)
committerDmitry Dulepov <dmitry@typo3.org>
Wed, 6 Feb 2013 13:50:54 +0000 (14:50 +0100)
If $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'] or
$TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'] are set in the Install
tool, cached TS will not be found in cache. This would result in TS
parsing every time when there are USER_INT objects on the page.
Generally it will slow down the page with USER_INT objects by at least
300% comparing to the cached version.

Change-Id: Ia0fd65a35897c71d60c48c0b03098ce67ad16c70
Resolves: #43540
Releases: 4.5, 4.6, 4.7, 6.0, 6.1
Reviewed-on: https://review.typo3.org/16939
Reviewed-by: Adrian Dymorz
Tested-by: Adrian Dymorz
Reviewed-by: Stefan Neufeind
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Sebastian Michaelsen
Reviewed-by: Dmitry Dulepov
Tested-by: Dmitry Dulepov
typo3/sysext/core/Classes/TypoScript/TemplateService.php

index f5c9fed..6601b13 100644 (file)
@@ -300,6 +300,13 @@ class TemplateService {
        public $MPmap = '';
 
        /**
+        * TRUE after the default TS is added during parsing. This prevents double addition of the same TS code.
+        *
+        * @var boolean
+        */
+       protected $defaultTSAdded = FALSE;
+
+       /**
         * Initialize
         * MUST be called directly after creating a new template-object
         *
@@ -452,7 +459,14 @@ class TemplateService {
                        if ($setupData && !$this->forceTemplateParsing) {
                                // If TypoScript setup structure was cached we unserialize it here:
                                $this->setup = unserialize($setupData);
+                               if ($this->tt_track) {
+                                       $GLOBALS['TT']->setTSLogMessage('Using cached TS template data');
+                               }
                        } else {
+                               if ($this->tt_track) {
+                                       $GLOBALS['TT']->setTSLogMessage('Not using any cached TS data');
+                               }
+
                                // Make configuration
                                $this->generateConfig();
                                // This stores the template hash thing
@@ -517,8 +531,9 @@ class TemplateService {
                $this->config = array();
                $this->rowSum = array();
                $this->hierarchyInfoToRoot = array();
-               // Is the TOTAL rootline
                $this->absoluteRootLine = $theRootLine;
+               $this->defaultTSAdded = FALSE;
+
                reset($this->absoluteRootLine);
                $c = count($this->absoluteRootLine);
                for ($a = 0; $a < $c; $a++) {
@@ -551,6 +566,13 @@ class TemplateService {
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        $this->rootLine[] = $this->absoluteRootLine[$a];
                }
+
+               if (!$this->defaultTSAdded) {
+                       array_unshift($this->constants, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
+                       array_unshift($this->config, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
+                       $this->defaultTSAdded = TRUE;
+               }
+
                $this->processIncludes();
        }
 
@@ -825,11 +847,13 @@ class TemplateService {
         * @todo Define visibility
         */
        public function generateConfig() {
-               // Add default TS for all three code types:
-               array_unshift($this->constants, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
-               // Adding default TS/constants
-               array_unshift($this->config, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
-               // Adding default TS/setup
+               if (!$this->defaultTSAdded) {
+                       // Add default TS for all code types
+                       array_unshift($this->constants, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
+                       array_unshift($this->config, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
+                       $this->defaultTSAdded = TRUE;
+               }
+
                // Parse the TypoScript code text for include-instructions!
                $this->processIncludes();
                // These vars are also set lateron...
@@ -1538,4 +1562,4 @@ class TemplateService {
 }
 
 
-?>
\ No newline at end of file
+?>