Fixed bug #13669: Performance: Inefficient fetch of templates from table sys_template...
authorBenni Mack <benni.mack@typo3.org>
Sun, 7 Mar 2010 09:16:58 +0000 (09:16 +0000)
committerBenni Mack <benni.mack@typo3.org>
Sun, 7 Mar 2010 09:16:58 +0000 (09:16 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7086 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_tstemplate.php

index ac482d5..3c496aa 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-03-07  Benjamin Mack  <benni@typo3.org>
+
+       * Fixed bug #13669: Performance: Inefficient fetch of templates from table sys_template (Thanks to Alexander Weggerle)
+
 2010-03-06  Oliver Hader  <oliver@typo3.org>
 
        * Fixed bug #1104: Setting file fields in TCA to "required" makes it impossible to save the record (thanks to Ingmar Schlecht & Tobias Liebig)
index 0097534..8356959 100644 (file)
@@ -571,18 +571,30 @@ class t3lib_TStemplate    {
                                        }
                                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                                }
-                       } else {        // NORMAL OPERATION:
-                               $basedOnArr = t3lib_div::intExplode(',', $row['basedOn']);
-                               foreach ($basedOnArr as $id) { // traversing list
-                                       if (!t3lib_div::inList($idList,'sys_'.$id))     {       // if $id is not allready included ...
-                                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.intval($id).' '.$this->whereClause);
-                                               if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {       // there was a template, then we fetch that
-                                                       $this->versionOL($subrow);
-                                                       if (is_array($subrow))  {
-                                                               $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
-                                                       }
-                                               }
-                                               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+                       } else {
+                                       // Normal Operation, which is to include the "based-on" sys_templates, 
+                                       // if they are not already included, and maintaining the sorting of the templates
+                               $basedOnIds = t3lib_div::intExplode(',', $row['basedOn']);
+
+                                       // skip template if it's already included
+                               foreach ($basedOnIds as $key => $basedOnId) {
+                                       if (t3lib_div::inList($idList, 'sys_' . $basedOnId)) {
+                                               unset($basedOnIds[$key]);
+                                       }
+                               }
+
+                               $subTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                       '*', 'sys_template',
+                                       'uid IN (' . implode(',', $basedOnIds) . ') ' . $this->whereClause,
+                                       '', '', '',
+                                       'uid'   // the associative array that is returned will contain this field as key
+                               );
+
+                                       // traversing list again to ensure the sorting of the templates
+                               foreach ($basedOnIds as $id) { 
+                                       if (is_array($subTemplates[$id])) {
+                                               $this->versionOL($subTemplates[$id]);
+                                               $this->processTemplate($subTemplates[$id], $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID);
                                        }
                                }
                        }