[BUGFIX] Use less memory in CLI lowlevel_refindex 73/38573/5
authorChristian Weiske <christian.weiske@netresearch.de>
Thu, 9 Apr 2015 08:44:25 +0000 (10:44 +0200)
committerMarkus Klein <klein.t3@reelworx.at>
Thu, 9 Apr 2015 12:33:32 +0000 (14:33 +0200)
Fetch each row when we actually need its data instead of fetching all
rows at once.
This saves quite a lot memory on tables with many records.

Change-Id: I7493f206c94cba5ee3f3ff85d84dc70d91dd66aa
Resolves: #17774
Releases: master, 6.2
Reviewed-on: http://review.typo3.org/38573
Reviewed-by: Stephan Großberndt <stephan@grossberndt.de>
Tested-by: Stephan Großberndt <stephan@grossberndt.de>
Reviewed-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Tested-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/core/Classes/Database/ReferenceIndex.php

index a9dba67..623c8d7 100644 (file)
@@ -1091,8 +1091,8 @@ class ReferenceIndex {
                        }
                        // Traverse all records in tables, including deleted records:
                        $fieldNames = (BackendUtility::isTableWorkspaceEnabled($tableName) ? 'uid,t3ver_wsid' : 'uid');
-                       $allRecs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($fieldNames, $tableName, '1=1');
-                       if (!is_array($allRecs)) {
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fieldNames, $tableName, '1=1');
+                       if ($GLOBALS['TYPO3_DB']->sql_error()) {
                                // Table exists in $TCA but does not exist in the database
                                GeneralUtility::sysLog(sprintf('Table "%s" exists in $TCA but does not exist in the database. You should run the Database Analyzer in the Install Tool to fix this.', $tableName), 'core', GeneralUtility::SYSLOG_SEVERITY_ERROR);
                                continue;
@@ -1100,7 +1100,7 @@ class ReferenceIndex {
                        $tableNames[] = $tableName;
                        $tableCount++;
                        $uidList = array(0);
-                       foreach ($allRecs as $recdat) {
+                       while ($recdat = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                                /** @var $refIndexObj ReferenceIndex */
                                $refIndexObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class);
                                if (isset($recdat['t3ver_wsid'])) {
@@ -1117,6 +1117,8 @@ class ReferenceIndex {
                                        }
                                }
                        }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+
                        // Searching lost indexes for this table:
                        $where = 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($tableName, 'sys_refindex') . ' AND recuid NOT IN (' . implode(',', $uidList) . ')';
                        $lostIndexes = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('hash', 'sys_refindex', $where);