diff options
author | Joas Schilling <coding@schilljs.com> | 2023-11-03 16:51:20 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-11-03 16:51:20 +0100 |
commit | 45cd929abeddb7fda96997983ae469b003442425 (patch) | |
tree | 3295be19433bc52f8d930165b6a79a39cc44a7a4 | |
parent | 6f39d82031202a2a8d1fb81ea448a2ffdc52cc29 (diff) | |
download | nextcloud-server-bugfix/noid/improve-installation-speed-of-oracle.tar.gz nextcloud-server-bugfix/noid/improve-installation-speed-of-oracle.zip |
fix(install): Improve schema migration speed of Oraclebugfix/noid/improve-installation-speed-of-oracle
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/private/DB/MigrationService.php | 46 | ||||
-rw-r--r-- | lib/private/DB/SchemaWrapper.php | 4 |
2 files changed, 26 insertions, 24 deletions
diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index 60f9b65cd5f..4de693f2d6c 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -399,7 +399,7 @@ class MigrationService { $toBeExecuted = $this->getMigrationsToExecute($to); foreach ($toBeExecuted as $version) { try { - $this->executeStep($version, $schemaOnly); + $this->executeStep($version); } catch (\Exception $e) { // The exception itself does not contain the name of the migration, // so we wrap it here, to make debugging easier. @@ -420,13 +420,16 @@ class MigrationService { return; } - $toSchema = null; + $toSchema = $beforeSchema = null; foreach ($toBeExecuted as $version) { $this->output->debug('- Reading ' . $version); $instance = $this->createInstance($version); - $toSchema = $instance->changeSchema($this->output, function () use ($toSchema): ISchemaWrapper { - return $toSchema ?: new SchemaWrapper($this->connection); + $toSchema = $instance->changeSchema($this->output, function () use ($toSchema, &$beforeSchema): ISchemaWrapper { + if ($toSchema === null) { + $beforeSchema ??= $this->connection->createSchema(); + } + return $toSchema ?: new SchemaWrapper($this->connection, $beforeSchema); }, ['tablePrefix' => $this->connection->getPrefix()]) ?: $toSchema; } @@ -435,12 +438,12 @@ class MigrationService { $targetSchema = $toSchema->getWrappedSchema(); $this->ensureUniqueNamesConstraints($targetSchema); if ($this->checkOracle) { - $beforeSchema = $this->connection->createSchema(); + $beforeSchema ??= $this->connection->createSchema(); $this->ensureOracleConstraints($beforeSchema, $targetSchema, strlen($this->connection->getPrefix())); } $this->output->debug('- Migrate database schema'); - $this->connection->migrateToSchema($targetSchema); + $this->connection->migrateToSchema($targetSchema, false, $beforeSchema); $toSchema->performDropTableCalls(); } @@ -496,38 +499,37 @@ class MigrationService { * Executes one explicit version * * @param string $version - * @param bool $schemaOnly * @throws \InvalidArgumentException */ - public function executeStep($version, $schemaOnly = false) { + public function executeStep($version) { $instance = $this->createInstance($version); - if (!$schemaOnly) { - $instance->preSchemaChange($this->output, function (): ISchemaWrapper { - return new SchemaWrapper($this->connection); - }, ['tablePrefix' => $this->connection->getPrefix()]); - } - - $toSchema = $instance->changeSchema($this->output, function (): ISchemaWrapper { + $beforeSchema = null; + $instance->preSchemaChange($this->output, function () use (&$beforeSchema): ISchemaWrapper { + $beforeSchema = $this->connection->createSchema(); return new SchemaWrapper($this->connection); }, ['tablePrefix' => $this->connection->getPrefix()]); + $toSchema = $instance->changeSchema($this->output, function () use (&$beforeSchema): ISchemaWrapper { + $beforeSchema ??= $this->connection->createSchema(); + return new SchemaWrapper($this->connection, $beforeSchema); + }, ['tablePrefix' => $this->connection->getPrefix()]); + if ($toSchema instanceof SchemaWrapper) { $targetSchema = $toSchema->getWrappedSchema(); $this->ensureUniqueNamesConstraints($targetSchema); if ($this->checkOracle) { - $sourceSchema = $this->connection->createSchema(); - $this->ensureOracleConstraints($sourceSchema, $targetSchema, strlen($this->connection->getPrefix())); + $beforeSchema ??= $this->connection->createSchema(); + $this->ensureOracleConstraints($beforeSchema, $targetSchema, strlen($this->connection->getPrefix())); } $this->connection->migrateToSchema($targetSchema); $toSchema->performDropTableCalls(); } - if (!$schemaOnly) { - $instance->postSchemaChange($this->output, function (): ISchemaWrapper { - return new SchemaWrapper($this->connection); - }, ['tablePrefix' => $this->connection->getPrefix()]); - } + $instance->postSchemaChange($this->output, function () use (&$beforeSchema): ISchemaWrapper { + $beforeSchema ??= $this->connection->createSchema(); + return new SchemaWrapper($this->connection, $beforeSchema); + }, ['tablePrefix' => $this->connection->getPrefix()]); $this->markAsExecuted($version); } diff --git a/lib/private/DB/SchemaWrapper.php b/lib/private/DB/SchemaWrapper.php index 9dae9ab6248..410ca470aae 100644 --- a/lib/private/DB/SchemaWrapper.php +++ b/lib/private/DB/SchemaWrapper.php @@ -38,9 +38,9 @@ class SchemaWrapper implements ISchemaWrapper { /** @var array */ protected $tablesToDelete = []; - public function __construct(Connection $connection) { + public function __construct(Connection $connection, ?Schema $beforeSchema = null) { $this->connection = $connection; - $this->schema = $this->connection->createSchema(); + $this->schema = $beforeSchema !== null ? $beforeSchema : $this->connection->createSchema(); } public function getWrappedSchema() { |