diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-02-16 18:18:56 +0100 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-02-16 18:28:06 +0100 |
commit | db6927ee0530d2e352725dc0f6d75e8db8723587 (patch) | |
tree | e8bfd2b055745f818958533e8ece0405e24a9e7f /core | |
parent | 1bfd001cf6add6cb99d5231502c8c19e8dce910a (diff) | |
download | nextcloud-server-db6927ee0530d2e352725dc0f6d75e8db8723587.tar.gz nextcloud-server-db6927ee0530d2e352725dc0f6d75e8db8723587.zip |
Improve performance when converting between DBs
Use a transaction when doing multiple inserts increase the writing
speed.
Ref: https://stackoverflow.com/a/68495887
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'core')
-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(''); } |