Revert "Optimize AbstractDatabaseObjectAction::update() for bulk processing"
authorMatthias Schmidt <gravatronics@live.com>
Sat, 27 Jul 2019 11:51:30 +0000 (13:51 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 27 Jul 2019 11:51:30 +0000 (13:51 +0200)
This reverts commit b50fd065f955d69708a8b093ea2d22717288cc53.
Close #2995

wcfsetup/install/files/lib/data/AbstractDatabaseObjectAction.class.php

index 332b2955d41dddc60d53899bd7d23363b836e7a1..1de72ecec4bdcba40a2b5b4e74f9414b3079a304 100644 (file)
@@ -363,60 +363,16 @@ abstract class AbstractDatabaseObjectAction implements IDatabaseObjectAction, ID
                        $this->readObjects();
                }
                
-               $tableName = call_user_func([$this->className, 'getDatabaseTableName']);
-               $indexName = call_user_func([$this->className, 'getDatabaseTableIndexName']);
-               
-               $itemsPerLoop = 1000;
-               $loopCount = ceil(count($this->objectIDs) / $itemsPerLoop);
-               
-               if (!empty($this->parameters['data'])) {
-                       $updateSQL = '';
-                       $statementParameters = [];
-                       foreach ($this->parameters['data'] as $key => $value) {
-                               if (!empty($updateSQL)) $updateSQL .= ', ';
-                               $updateSQL .= $key . ' = ?';
-                               $statementParameters[] = $value;
-                       }
-                       
-                       WCF::getDB()->beginTransaction();
-                       for ($i = 0; $i < $loopCount; $i++) {
-                               $batchObjectIDs = array_slice($this->objectIDs, $i * $itemsPerLoop, $itemsPerLoop);
-                               
-                               $conditionBuilder = new PreparedStatementConditionBuilder();
-                               $conditionBuilder->add($indexName . ' IN (?)', [$batchObjectIDs]);
-                               
-                               $sql = "UPDATE  " . $tableName . "
-                                       SET     " . $updateSQL . "
-                                       " . $conditionBuilder;
-                               $statement = WCF::getDB()->prepareStatement($sql);
-                               $statement->execute(array_merge($statementParameters, $conditionBuilder->getParameters()));
+               if (isset($this->parameters['data'])) {
+                       foreach ($this->getObjects() as $object) {
+                               $object->update($this->parameters['data']);
                        }
-                       WCF::getDB()->commitTransaction();
                }
                
-               if (!empty($this->parameters['counters'])) {
-                       $updateSQL = '';
-                       $statementParameters = [];
-                       foreach ($this->parameters['counters'] as $key => $value) {
-                               if (!empty($updateSQL)) $updateSQL .= ', ';
-                               $updateSQL .= $key . ' = ' . $key . ' + ?';
-                               $statementParameters[] = $value;
-                       }
-                       
-                       WCF::getDB()->beginTransaction();
-                       for ($i = 0; $i < $loopCount; $i++) {
-                               $batchObjectIDs = array_slice($this->objectIDs, $i * $itemsPerLoop, $itemsPerLoop);
-                               
-                               $conditionBuilder = new PreparedStatementConditionBuilder();
-                               $conditionBuilder->add($indexName . ' IN (?)', [$batchObjectIDs]);
-                               
-                               $sql = "UPDATE  " . $tableName . "
-                                       SET     " . $updateSQL . "
-                                       " . $conditionBuilder;
-                               $statement = WCF::getDB()->prepareStatement($sql);
-                               $statement->execute(array_merge($statementParameters, $conditionBuilder->getParameters()));
+               if (isset($this->parameters['counters'])) {
+                       foreach ($this->getObjects() as $object) {
+                               $object->updateCounters($this->parameters['counters']);
                        }
-                       WCF::getDB()->commitTransaction();
                }
        }