From ba820c5192fccb65c270445562f7fa3dc4bb7cc8 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sun, 29 Dec 2024 22:36:28 +0100 Subject: [PATCH 1/2] add connection role to SQL Log Panel queries --- psalm-baseline.xml | 1 + src/Database/Log/DebugLog.php | 5 +++++ templates/element/sql_log_panel.php | 2 ++ 3 files changed, 8 insertions(+) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 00ef8c53..50bb3f06 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2,6 +2,7 @@ + diff --git a/src/Database/Log/DebugLog.php b/src/Database/Log/DebugLog.php index a9e6d22b..596c83f4 100644 --- a/src/Database/Log/DebugLog.php +++ b/src/Database/Log/DebugLog.php @@ -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) { @@ -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; @@ -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) { diff --git a/templates/element/sql_log_panel.php b/templates/element/sql_log_panel.php index 7e6e6d52..83336081 100644 --- a/templates/element/sql_log_panel.php +++ b/templates/element/sql_log_panel.php @@ -69,6 +69,7 @@ Query Rows Took (ms) + Role @@ -90,6 +91,7 @@ + From dd4ec0694999e5a5de78ea086313d35a022c90a4 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sun, 29 Dec 2024 22:47:30 +0100 Subject: [PATCH 2/2] fix regex pattern in test --- tests/TestCase/ToolbarServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase/ToolbarServiceTest.php b/tests/TestCase/ToolbarServiceTest.php index 5e9a3b38..8d849352 100644 --- a/tests/TestCase/ToolbarServiceTest.php +++ b/tests/TestCase/ToolbarServiceTest.php @@ -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);