Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the performance of the database dumper #6946

Merged
merged 4 commits into from Feb 28, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions core-bundle/src/Doctrine/Backup/Dumper.php
Expand Up @@ -22,6 +22,8 @@

class Dumper implements DumperInterface
{
private array $quoteCache = [];

public function dump(Connection $connection, CreateConfig $config): \Generator
{
try {
Expand All @@ -32,10 +34,12 @@ public function dump(Connection $connection, CreateConfig $config): \Generator
}

throw new BackupManagerException($exception->getMessage(), 0, $exception);
} finally {
$this->quoteCache = [];
}
}

public function doDump(Connection $connection, CreateConfig $config): \Generator
private function doDump(Connection $connection, CreateConfig $config): \Generator
leofeyer marked this conversation as resolved.
Show resolved Hide resolved
{
yield 'SET FOREIGN_KEY_CHECKS = 0;';

Expand Down Expand Up @@ -76,7 +80,7 @@ private function disableQueryBuffering(Connection $connection): void
}

/**
* @param AbstractSchemaManager<AbstractPlatform> $schemaManager
* @phpstan-param AbstractSchemaManager<AbstractPlatform> $schemaManager
leofeyer marked this conversation as resolved.
Show resolved Hide resolved
*/
private function dumpViews(AbstractSchemaManager $schemaManager, AbstractPlatform $platform): \Generator
{
Expand Down Expand Up @@ -160,7 +164,16 @@ private function formatValueForDump(float|int|string|null $value, int $columnBin
return '0x'.bin2hex($value);
}

return $connection->quote($value);
if (isset($this->quoteCache[$value])) {
return $this->quoteCache[$value];
}

// Prevent the in-memory cache from growing forever on big databases
if (\count($this->quoteCache) >= 100000) {
$this->quoteCache = [];
}

return $this->quoteCache[$value] = $connection->quote($value);
}

/**
Expand Down