Skip to content

Commit ad6577d

Browse files
Tigrovvjik
andauthored
Do not call CommandInterface::getRawSql() if no logger or profiler (#781)
Co-authored-by: Sergei Predvoditelev <[email protected]>
1 parent c4c4a9d commit ad6577d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
`DbArrayHelper::populate()` methods to `array[]` (@vjik)
99
- Enh #779: Specify populate closure type in `BatchQueryResultInterface` (@vjik)
1010
- Enh #778: Deprecate unnecessary argument `$rawSql` of `AbstractCommand::internalExecute()` (@Tigrov)
11+
- Enh #781: Skip calling `CommandInterface::getRawSql()` if no `logger` or `profiler` is set (@Tigrov)
1112
- Enh #785: Refactor `AbstractCommand::getRawSql()` (@Tigrov)
1213
- Bug #785: Fix bug of `AbstractCommand::getRawSql()` when a param value is `Stringable` object (@Tigrov)
1314
- Enh #786: Refactor `AbstractSchema::getDataType()` (@Tigrov)

src/Driver/Pdo/AbstractPdoCommand.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,21 @@ protected function logQuery(string $rawSql, string $category): void
265265

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

271-
$this->logQuery($rawSql, $logCategory);
270+
if ($this->logger !== null) {
271+
$rawSql = $this->getRawSql();
272+
$this->logQuery($rawSql, $logCategory);
273+
}
272274

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

275-
$this->profiler?->begin($rawSql, $queryContext);
277+
/**
278+
* @psalm-var string $rawSql
279+
* @psalm-suppress RedundantConditionGivenDocblockType
280+
* @psalm-suppress DocblockTypeContradiction
281+
*/
282+
$this->profiler?->begin($rawSql ??= $this->getRawSql(), $queryContext);
276283
try {
277284
/** @psalm-var mixed $result */
278285
$result = parent::queryInternal($queryMode);

0 commit comments

Comments
 (0)