[BUGFIX] TS is fetched from cache incorrectly sometimes 77/24177/2
authorDmitry Dulepov <dmitry.dulepov@gmail.com>
Mon, 3 Dec 2012 09:40:25 +0000 (13:40 +0400)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Mon, 30 Sep 2013 17:54:55 +0000 (19:54 +0200)
If $TYPO3_CONF_VARS['FE']['defaultTypoScript_constants'] or
$TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'] are set through
the PHP code, 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. It may slow down the page with USER_INT objects
by about 300% comparing to the cached version.

This change is re-added after it got reverted due to lack of reviews in
Ia0fd65a35897c71d60c48c0b03098ce67ad16c70.

Change-Id: Ief3a065451644423b236489729716b906f3d4500
Resolves: #43540
Releases: 4.5, 4.7, 6.0, 6.1, 6.2
Reviewed-on: https://review.typo3.org/24177
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
typo3/sysext/core/Classes/TypoScript/TemplateService.php

index 66c641c..7cc71ed 100644 (file)
@@ -314,6 +314,15 @@ class TemplateService {
        protected $processExtensionStatics = FALSE;
 
        /**
+        * Set to TRUE after the default TypoScript was added during parsing.
+        * This prevents double inclusion of the same TypoScript code.
+        *
+        * @see addDefaultTypoScript()
+        * @var boolean
+        */
+       protected $isDefaultTypoScriptAdded = FALSE;
+
+       /**
         * @return boolean
         */
        public function getProcessExtensionStatics() {
@@ -475,7 +484,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
@@ -540,8 +556,9 @@ class TemplateService {
                $this->config = array();
                $this->rowSum = array();
                $this->hierarchyInfoToRoot = array();
-               // Is the TOTAL rootline
                $this->absoluteRootLine = $theRootLine;
+               $this->isDefaultTyposcriptAdded = FALSE;
+
                reset($this->absoluteRootLine);
                $c = count($this->absoluteRootLine);
                for ($a = 0; $a < $c; $a++) {
@@ -574,10 +591,15 @@ class TemplateService {
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        $this->rootLine[] = $this->absoluteRootLine[$a];
                }
+
                // Process extension static files if not done yet, but explicitly requested
                if (!$this->extensionStaticsProcessed && $this->processExtensionStatics) {
                        $this->addExtensionStatics('sys_0', 'sys_0', 0, array());
                }
+
+               // Add the global default TypoScript from the TYPO3_CONF_VARS
+               $this->addDefaultTypoScript();
+
                $this->processIncludes();
        }
 
@@ -886,11 +908,9 @@ 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
+               // Add default TS for all code types
+               $this->addDefaultTypoScript();
+
                // Parse the TypoScript code text for include-instructions!
                $this->processIncludes();
                // These vars are also set lateron...
@@ -1602,7 +1622,27 @@ class TemplateService {
                }
        }
 
-}
+       /**
+        * Adds the TypoScript from the global array.
+        * The class property isDefaultTypoScriptAdded ensures
+        * that the adding only happens once.
+        *
+        * @return void
+        * @see isDefaultTypoScriptAdded
+        */
+       protected function addDefaultTypoScript() {
+                       // Add default TS for all code types, if not done already
+               if (!$this->isDefaultTypoScriptAdded) {
+                       if (!empty($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants'])) {
+                               array_unshift($this->constants, (string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
+                       }
+                       if (!empty($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'])) {
+                               array_unshift($this->config, (string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
+                       }
+                       $this->isDefaultTypoScriptAdded = TRUE;
+               }
+       }
 
+}
 
 ?>