Skip to content

Commit

Permalink
Doctrine - reworked resolving of connection name to be done only once…
Browse files Browse the repository at this point in the history
… and work with all DBAL versions.
  • Loading branch information
itsgoingd committed Aug 4, 2022
1 parent 8bfcaf4 commit bd13e76
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Clockwork/DataSource/DBALDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ class DBALDataSource extends DataSource implements SQLLogger
// DBAL connection
protected $connection;

// DBAL connection name
protected $connectionName;

// Create a new data source instance, takes a DBAL connection instance as an argument
public function __construct(Connection $connection)
{
$this->connection = $connection;
$this->connectionName = $this->connection->getDatabase();

$configuration = $this->connection->getConfiguration();
$currentLogger = $configuration->getSQLLogger();
Expand Down Expand Up @@ -79,9 +83,7 @@ protected function registerQuery($query)
'query' => $this->createRunnableQuery($query['query'], $query['params'], $query['types']),
'bindings' => $query['params'],
'duration' => (microtime(true) - $query['time']) * 1000,
// Resolve connection only on DBAL versions older that 3.0, as resolving connection on newer DBAL always
// executes an additional SQL query, effectively doubling the number of executed queries
'connection' => class_exists(Doctrine\DBAL\DBALException::class) ? $this->connection->getDatabase() : null,
'connection' => $this->connectionName,
'time' => $query['time']
];

Expand Down

0 comments on commit bd13e76

Please sign in to comment.