diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2022-02-24 23:25:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-24 23:25:41 +0100 |
commit | abbbae1fc83635e331a750d77062644a54631f93 (patch) | |
tree | 06066453b3b165cd82c7d738492817c214a3f303 | |
parent | d7e55e272e70f4d3b3b4e74d51ab2001f4d037a7 (diff) | |
parent | db6927ee0530d2e352725dc0f6d75e8db8723587 (diff) | |
download | nextcloud-server-abbbae1fc83635e331a750d77062644a54631f93.tar.gz nextcloud-server-abbbae1fc83635e331a750d77062644a54631f93.zip |
Merge pull request #31219 from nextcloud/fix/performance-db-convert
Improve performance when converting between DBs
-rw-r--r-- | core/Command/Db/ConvertType.php | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/core/Command/Db/ConvertType.php b/core/Command/Db/ConvertType.php index 27f3147b81d..754cbd08812 100644 --- a/core/Command/Db/ConvertType.php +++ b/core/Command/Db/ConvertType.php @@ -353,27 +353,37 @@ class ConvertType extends Command implements CompletionAwareInterface { $result = $query->execute(); - while ($row = $result->fetch()) { - $progress->advance(); - if (!$parametersCreated) { - foreach ($row as $key => $value) { - $insertQuery->setValue($key, $insertQuery->createParameter($key)); + try { + $toDB->beginTransaction(); + + while ($row = $result->fetch()) { + $progress->advance(); + if (!$parametersCreated) { + foreach ($row as $key => $value) { + $insertQuery->setValue($key, $insertQuery->createParameter($key)); + } + $parametersCreated = true; } - $parametersCreated = true; - } - foreach ($row as $key => $value) { - $type = $this->getColumnType($table, $key); - if ($type !== false) { - $insertQuery->setParameter($key, $value, $type); - } else { - $insertQuery->setParameter($key, $value); + foreach ($row as $key => $value) { + $type = $this->getColumnType($table, $key); + if ($type !== false) { + $insertQuery->setParameter($key, $value, $type); + } else { + $insertQuery->setParameter($key, $value); + } } + $insertQuery->execute(); } - $insertQuery->execute(); + $result->closeCursor(); + + $toDB->commit(); + } catch (\Throwable $e) { + $toDB->rollBack(); + throw $e; } - $result->closeCursor(); } + $progress->finish(); $output->writeln(''); } |