Skip to content

Commit

Permalink
Merge pull request #1033 from cakephp/5.x-connection-role
Browse files Browse the repository at this point in the history
add connection role to SQL Log Panel queries
  • Loading branch information
LordSimal authored Dec 30, 2024
2 parents cc0d0b9 + dd4ec06 commit b83ec9e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/Database/Log/DebugLog.php">
<InternalMethod>
<code><![CDATA[getContext]]></code>
<code><![CDATA[jsonSerialize]]></code>
</InternalMethod>
</file>
Expand Down
5 changes: 5 additions & 0 deletions src/Database/Log/DebugLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public function totalTime(): float
*/
public function log($level, string|Stringable $message, array $context = []): void
{
/** @var \Cake\Database\Log\LoggedQuery|object|null $query */
$query = $context['query'] ?? null;

if ($this->_logger) {
Expand All @@ -153,6 +154,9 @@ public function log($level, string|Stringable $message, array $context = []): vo
], JSON_PRETTY_PRINT),
'took' => $took,
'rows' => $context['response']['hits']['total']['value'] ?? $context['response']['hits']['total'] ?? 0,
'inTransaction' => $this->inTransaction,
'isCommitOrRollback' => false,
'role' => '',
];

return;
Expand Down Expand Up @@ -183,6 +187,7 @@ public function log($level, string|Stringable $message, array $context = []): vo
'rows' => $data['numRows'],
'inTransaction' => $this->inTransaction,
'isCommitOrRollback' => $isCommitOrRollback,
'role' => $query->getContext()['role'],
];

if ($isCommitOrRollback) {
Expand Down
2 changes: 2 additions & 0 deletions templates/element/sql_log_panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<th>Query</th>
<th>Rows</th>
<th>Took (ms)</th>
<th>Role</th>
</tr>
</thead>
<tbody>
Expand All @@ -90,6 +91,7 @@
</td>
<td><?= h($query['rows']) ?></td>
<td><?= h($query['took']) ?></td>
<td><?= h($query['role']) ?></td>
</tr>
<?php if ($query['isCommitOrRollback']): ?>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/ToolbarServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function testSaveData()
$this->assertSame('Timer', $result->panels[11]->panel);
$this->assertSame('DebugKit.timer_panel', $result->panels[11]->element);
$this->assertMatchesRegularExpression(
'/\d+\.\d+\s[ms]+\s+\/\s+\d+\.\d+\s+[mbMB]+/',
'/\d+\.\d+\s[ms]+\s+\/\s+\d+\.?\d+\s+[mbMB]+/',
$result->panels[11]->summary
);
$this->assertSame('Timer', $result->panels[11]->title);
Expand Down

0 comments on commit b83ec9e

Please sign in to comment.