Fixed bug #11722: Performance improvement: speed up function t3lib_BEfunc::selectVers...
authorRupert Germann <rupi@gmx.li>
Fri, 14 Aug 2009 19:38:57 +0000 (19:38 +0000)
committerRupert Germann <rupi@gmx.li>
Fri, 14 Aug 2009 19:38:57 +0000 (19:38 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5790 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_befunc.php
typo3/class.db_list_extra.inc

index f9e7100..8d885bc 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2009-08-14  Rupert Germann  <rupi@gmx.li>
 
        * Fixed bug #11718: Performance improvement: speed up function t3lib_iconWorks::skinImg() by caching the results
+       * Fixed bug #11722: Performance improvement: speed up function t3lib_BEfunc::selectVersionsOfRecord
        * Followup to 11474: updated performance section in NEWT.txt
 
 2009-08-14  Ingo Renner  <ingo@typo3.org>
index a5905f9..7537e3d 100644 (file)
@@ -3521,31 +3521,40 @@ final class t3lib_BEfunc {
         * @param       string          Field list to select
         * @param       integer         Workspace ID, if zero all versions regardless of workspace is found.
         * @param       boolean         If set, deleted-flagged versions are included! (Only for clean-up script!)
+        * @param       array           The current record
         * @return      array           Array of versions of table/uid
         */
-       public static function selectVersionsOfRecord($table, $uid, $fields = '*', $workspace = 0, $includeDeletedRecords = FALSE) {
+       public static function selectVersionsOfRecord($table, $uid, $fields = '*', $workspace = 0, $includeDeletedRecords = FALSE, $row = NULL) {
                global $TCA;
 
-               if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS'])       {
+               $realPid = 0;
+               $outputRows = array();
 
-                       $realPid = 0;
-                       $outputRows = array();
-
-                               // Select UID version:
-                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                               $fields,
-                               $table,
-                               'uid='.intval($uid).
-                                       ($includeDeletedRecords ? '' : t3lib_BEfunc::deleteClause($table)),
-                               '',
-                               't3ver_id DESC'
-                       );
+               if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS']) {
 
-                                               // Add rows to output array:
-                       while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
+                       if (is_array($row) && !$includeDeletedRecords) {
                                $row['_CURRENT_VERSION'] = TRUE;
                                $realPid = $row['pid'];
                                $outputRows[] = $row;
+                       } else {
+                                       // Select UID version:
+                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                                       $fields,
+                                       $table,
+                                       'uid=' . intval($uid) .
+                                               ($includeDeletedRecords ? '' : t3lib_BEfunc::deleteClause($table))
+                               );
+
+                                       // Add rows to output array:
+                               if ($res) {
+                                       $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+                                       if ($row) {
+                                               $row['_CURRENT_VERSION'] = TRUE;
+                                               $realPid = $row['pid'];
+                                               $outputRows[] = $row;
+                                       }
+                                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+                               }
                        }
 
                                // Select all offline versions of record:
@@ -3559,14 +3568,14 @@ final class t3lib_BEfunc {
                        );
 
                                // Add rows to output array:
-                       while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
+                       while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) {
                                $outputRows[] = $row;
                        }
 
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
 
                                // Set real-pid:
-                       foreach($outputRows as $idx => $oRow) {
+                       foreach ($outputRows as $idx => $oRow) {
                                $outputRows[$idx]['_REAL_PID'] = $realPid;
                        }
 
index 8659317..bd575ea 100644 (file)
@@ -1122,7 +1122,7 @@ class localRecordList extends recordList {
 
                                        // Versioning:
                                if (t3lib_extMgm::isLoaded('version'))  {
-                                       $vers = t3lib_BEfunc::selectVersionsOfRecord($table, $row['uid'], 'uid', $GLOBALS['BE_USER']->workspace);
+                                       $vers = t3lib_BEfunc::selectVersionsOfRecord($table, $row['uid'], 'uid', $GLOBALS['BE_USER']->workspace, FALSE, $row);
                                        if (is_array($vers))    {       // If table can be versionized.
                                                if (count($vers)>1)     {
                                                        $class = 'typo3-ctrl-versioning-multipleVersions';