Skip to content

Commit

Permalink
Do not call CommandInterface::getRawSql() if no logger or `profil…
Browse files Browse the repository at this point in the history
…er` (#781)

Co-authored-by: Sergei Predvoditelev <[email protected]>
  • Loading branch information
Tigrov and vjik authored Nov 27, 2023
1 parent c4c4a9d commit ad6577d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
`DbArrayHelper::populate()` methods to `array[]` (@vjik)
- Enh #779: Specify populate closure type in `BatchQueryResultInterface` (@vjik)
- Enh #778: Deprecate unnecessary argument `$rawSql` of `AbstractCommand::internalExecute()` (@Tigrov)
- Enh #781: Skip calling `CommandInterface::getRawSql()` if no `logger` or `profiler` is set (@Tigrov)
- Enh #785: Refactor `AbstractCommand::getRawSql()` (@Tigrov)
- Bug #785: Fix bug of `AbstractCommand::getRawSql()` when a param value is `Stringable` object (@Tigrov)
- Enh #786: Refactor `AbstractSchema::getDataType()` (@Tigrov)
Expand Down
13 changes: 10 additions & 3 deletions src/Driver/Pdo/AbstractPdoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,21 @@ protected function logQuery(string $rawSql, string $category): void

protected function queryInternal(int $queryMode): mixed
{
$rawSql = $this->getRawSql();
$logCategory = self::class . '::' . $this->getQueryMode($queryMode);

$this->logQuery($rawSql, $logCategory);
if ($this->logger !== null) {
$rawSql = $this->getRawSql();
$this->logQuery($rawSql, $logCategory);
}

$queryContext = new CommandContext(__METHOD__, $logCategory, $this->getSql(), $this->getParams());

$this->profiler?->begin($rawSql, $queryContext);
/**
* @psalm-var string $rawSql
* @psalm-suppress RedundantConditionGivenDocblockType
* @psalm-suppress DocblockTypeContradiction
*/
$this->profiler?->begin($rawSql ??= $this->getRawSql(), $queryContext);
try {
/** @psalm-var mixed $result */
$result = parent::queryInternal($queryMode);
Expand Down

0 comments on commit ad6577d

Please sign in to comment.