[CLEANUP] Cleanup of method updateRefIndexTable 22/52722/2
authorAndreas Allacher <andreas@allacher.com>
Thu, 9 Mar 2017 11:45:13 +0000 (12:45 +0100)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Fri, 5 May 2017 12:02:52 +0000 (14:02 +0200)
Limit the selected SQL fields to hash value only, since this
is sufficient for the processing. Use a boolean value for
$currentRelations to reduces memory footprint.

Resolves: #80207
Releases: master, 8.7
Change-Id: I323fa797b221c915848fc63cef78fb752a55ea26
Reviewed-on: https://review.typo3.org/52722
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
typo3/sysext/core/Classes/Database/ReferenceIndex.php

index f56a3ba..66fb1f7 100644 (file)
@@ -213,7 +213,7 @@ class ReferenceIndex
         // No restrictions are needed, since sys_refindex is not a TCA table
         $queryBuilder = $connection->createQueryBuilder();
         $queryBuilder->getRestrictions()->removeAll();
-        $queryResult = $queryBuilder->select('*')->from('sys_refindex')->where(
+        $queryResult = $queryBuilder->select('hash')->from('sys_refindex')->where(
             $queryBuilder->expr()->eq('tablename', $queryBuilder->createNamedParameter($tableName, \PDO::PARAM_STR)),
             $queryBuilder->expr()->eq('recuid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)),
             $queryBuilder->expr()->eq(
@@ -221,9 +221,9 @@ class ReferenceIndex
                 $queryBuilder->createNamedParameter($this->getWorkspaceId(), \PDO::PARAM_INT)
             )
         )->execute();
-        $currentRelations = [];
+        $currentRelationHashes = [];
         while ($relation = $queryResult->fetch()) {
-            $currentRelations[$relation['hash']] = $currentRelations;
+            $currentRelationHashes[$relation['hash']] = true;
         }
 
         // If the table has fields which could contain relations and the record does exist (including deleted-flagged)
@@ -260,8 +260,8 @@ class ReferenceIndex
 
                     // First, check if already indexed and if so, unset that row
                     // (so in the end we know which rows to remove!)
-                    if (isset($currentRelations[$relation['hash']])) {
-                        unset($currentRelations[$relation['hash']]);
+                    if (isset($currentRelationHashes[$relation['hash']])) {
+                        unset($currentRelationHashes[$relation['hash']]);
                         $result['keptNodes']++;
                         $relation['_ACTION'] = 'KEPT';
                     } else {
@@ -279,8 +279,8 @@ class ReferenceIndex
         }
 
         // If any old are left, remove them:
-        if (!empty($currentRelations)) {
-            $hashList = array_keys($currentRelations);
+        if (!empty($currentRelationHashes)) {
+            $hashList = array_keys($currentRelationHashes);
             if (!empty($hashList)) {
                 $result['deletedNodes'] = count($hashList);
                 $result['deletedNodes_hashList'] = implode(',', $hashList);