Skip to content

Commit

Permalink
Gate MySQL-only optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
linc committed Dec 24, 2022
1 parent b811821 commit 6a037a0
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,10 @@ public function newConnection(): Connection
{
$this->connection = $this->dbm->getConnection($this->alias);

// Always disable data integrity checks.
$this->connection->unprepared("SET foreign_key_checks = 0");

// Set the timezone to UTC. Avoid named timezones because they may not be loaded.
$this->connection->unprepared("SET time_zone = '+00:00'");

// Log all queries if debug mode is enabled.
if (\Porter\Config::getInstance()->debugEnabled()) {
// See ${hostname}.log in datadir (find with `SHOW GLOBAL VARIABLES LIKE 'datadir'`)
$this->connection->unprepared("SET GLOBAL general_log = 1");
if ($this->connection->getDriverName() === 'mysql') {
$this->optimizeMySQL();
}

return $this->connection;
}

Expand All @@ -132,4 +125,22 @@ public function translateConfig(array $config): array

return $config;
}

/**
* Perform MySQL-specific connection optimizations.
*/
protected function optimizeMySQL(): void
{
// Always disable data integrity checks.
$this->connection->unprepared("SET foreign_key_checks = 0");

// Set the timezone to UTC. Avoid named timezones because they may not be loaded.
$this->connection->unprepared("SET time_zone = '+00:00'");

// Log all queries if debug mode is enabled.
if (\Porter\Config::getInstance()->debugEnabled()) {
// See ${hostname}.log in datadir (find with `SHOW GLOBAL VARIABLES LIKE 'datadir'`)
$this->connection->unprepared("SET GLOBAL general_log = 1");
}
}
}

0 comments on commit 6a037a0

Please sign in to comment.