[TASK] DatabaseRecordList::createReferenceHtml uses too much memory 44/35744/3
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Fri, 2 Jan 2015 18:32:50 +0000 (19:32 +0100)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Fri, 2 Jan 2015 19:49:05 +0000 (20:49 +0100)
In order to reduce the amount of processing time spent while getting
the reference count the amount of records is being calculated by the
database now.

Resolves: #63394
Releases: master
Change-Id: Ib0a04678809d4ce16f0366c900c860da4450af64
Reviewed-on: http://review.typo3.org/35744
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
typo3/sysext/backend/Classes/Module/BaseScriptClass.php
typo3/sysext/backend/Classes/RecordList/AbstractRecordList.php
typo3/sysext/backend/Resources/Private/Language/locallang.xlf [new file with mode: 0644]
typo3/sysext/backend/Resources/Private/Language/locallang_errors.xlf [deleted file]
typo3/sysext/filelist/Classes/FileList.php
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

index ae8b554..3b42e4f 100644 (file)
@@ -328,7 +328,7 @@ class BaseScriptClass {
                if ($this->extObj === NULL) {
                        $flashMessage = GeneralUtility::makeInstance(
                                FlashMessage::class,
-                               $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_errors.xlf:no_modules_registered'),
+                               $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:no_modules_registered'),
                                $this->getLanguageService()->getLL('title'),
                                FlashMessage::ERROR
                        );
index 683c53f..3777193 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\RecordList;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\Utility\IconUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Lang\LanguageService;
 
 /**
  * Library with a single function addElement that returns table
@@ -435,30 +436,31 @@ abstract class AbstractRecordList {
         * Generates HTML code for a Reference tooltip out of
         * sys_refindex records you hand over
         *
-        * @param array $references array of records from sys_refindex table
+        * @param int $references number of records from sys_refindex table
         * @param string $launchViewParameter JavaScript String, which will be passed as parameters to top.launchView
         * @return string
         */
-       protected function generateReferenceToolTip(array $references, $launchViewParameter = '') {
-               $result = array();
-               foreach ($references as $reference) {
-                       $result[] = $reference['tablename'] . ':' . $reference['recuid'] . ':' . $reference['field'];
-                       if (strlen(implode(' / ', $result)) >= 100) {
-                               break;
-                       }
-               }
-               if (empty($result)) {
+       protected function generateReferenceToolTip($references, $launchViewParameter = '') {
+               if (!$references) {
                        $htmlCode = '-';
                } else {
                        $htmlCode = '<a href="#"';
                        if ($launchViewParameter !== '') {
                                $htmlCode .= ' onclick="' . htmlspecialchars(('top.launchView(' . $launchViewParameter . '); return false;')) . '"';
                        }
-                       $htmlCode .= ' title="' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(implode(' / ', $result), 100)) . '">';
-                       $htmlCode .= count($references);
+                       $htmlCode .= ' title="' . htmlspecialchars($this->getLanguageService()->sl('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:show_references') . ' (' .  $references . ')') . '">';
+                       $htmlCode .= $references;
                        $htmlCode .= '</a>';
                }
                return $htmlCode;
        }
 
+       /**
+        * Returns the language service
+        * @return LanguageService
+        */
+       protected function getLanguageService() {
+               return $GLOBALS['LANG'];
+       }
+
 }
diff --git a/typo3/sysext/backend/Resources/Private/Language/locallang.xlf b/typo3/sysext/backend/Resources/Private/Language/locallang.xlf
new file mode 100644 (file)
index 0000000..1b7d501
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
+       <file t3:id="1420197366" source-language="en" datatype="plaintext" original="messages" date="2015-01-02T11:16:11Z" product-name="backend">
+               <header/>
+               <body>
+                       <trans-unit id="no_modules_registered" xml:space="preserve">
+                               <source>No modules have been registered. Please contact your system administrator.</source>
+                       </trans-unit>
+                       <trans-unit id="show_references" xml:space="preserve">
+                               <source>Show references</source>
+                       </trans-unit>
+               </body>
+       </file>
+</xliff>
diff --git a/typo3/sysext/backend/Resources/Private/Language/locallang_errors.xlf b/typo3/sysext/backend/Resources/Private/Language/locallang_errors.xlf
deleted file mode 100644 (file)
index af75769..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
-       <file t3:id="1420197366" source-language="en" datatype="plaintext" original="messages" date="2015-01-02T11:16:11Z" product-name="backend">
-               <header/>
-               <body>
-                       <trans-unit id="no_modules_registered" xml:space="preserve">
-                               <source>No modules have been registered. Please contact your system administrator.</source>
-                       </trans-unit>
-               </body>
-       </file>
-</xliff>
index 9909409..df5afc7 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Filelist;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\Utility\IconUtility;
+use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Resource\FolderInterface;
 
@@ -879,8 +880,20 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                }
                // Look up the file in the sys_refindex.
                // Exclude sys_file_metadata records as these are no use references
-               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=\'sys_file\' AND ref_uid = ' . (int)$fileOrFolderObject->getUid() . ' AND deleted=0 AND tablename != "sys_file_metadata"');
-               return $this->generateReferenceToolTip($rows, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
+               $referenceCount = $this->getDatabaseConnection()->exec_SELECTcountRows(
+                       '*',
+                       'sys_refindex',
+                       'ref_table=\'sys_file\' AND ref_uid = ' . (int)$fileOrFolderObject->getUid() . ' AND deleted=0 AND tablename != "sys_file_metadata"'
+               );
+               return $this->generateReferenceToolTip($referenceCount, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
+       }
+
+       /**
+        * Returns the database connection
+        * @return DatabaseConnection
+        */
+       protected function getDatabaseConnection() {
+               return $GLOBALS['TYPO3_DB'];
        }
 
 }
index 94fef5a..a598ace 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Recordlist\RecordList;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
@@ -1486,13 +1487,13 @@ class DatabaseRecordList extends AbstractDatabaseRecordList {
         * @return string HTML of reference a link, will be empty if there are no
         */
        protected function createReferenceHtml($tableName, $uid) {
-               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                       'tablename, recuid, field',
+               $referenceCount = $this->getDatabaseConnection()->exec_SELECTcountRows(
+                       '*',
                        'sys_refindex',
-                       'ref_table = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($tableName, 'sys_refindex') .
+                       'ref_table = ' . $this->getDatabaseConnection()->fullQuoteStr($tableName, 'sys_refindex') .
                        ' AND ref_uid = ' . $uid . ' AND deleted = 0'
                );
-               return $this->generateReferenceToolTip($rows, '\'' . $tableName . '\', \'' . $uid . '\'');
+               return $this->generateReferenceToolTip($referenceCount, '\'' . $tableName . '\', \'' . $uid . '\'');
        }
 
        /**
@@ -1792,4 +1793,12 @@ class DatabaseRecordList extends AbstractDatabaseRecordList {
                die;
        }
 
+       /**
+        * Returns the database connection
+        * @return DatabaseConnection
+        */
+       protected function getDatabaseConnection() {
+               return $GLOBALS['TYPO3_DB'];
+       }
+
 }