From 32faf93ed95b83806c1793da36d5a300cb5b4c84 Mon Sep 17 00:00:00 2001 From: AmirReza Mehrbakhsh Date: Tue, 29 Apr 2025 08:45:52 +0200 Subject: [PATCH 1/2] Convert query duration time to milliseconds --- src/CommandSubscriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommandSubscriber.php b/src/CommandSubscriber.php index 569c7c909..5daa6e97a 100644 --- a/src/CommandSubscriber.php +++ b/src/CommandSubscriber.php @@ -48,6 +48,6 @@ private function logQuery(CommandSucceededEvent|CommandFailedEvent $event): void } } - $this->connection->logQuery(Document::fromPHP($command)->toCanonicalExtendedJSON(), [], $event->getDurationMicros()); + $this->connection->logQuery(Document::fromPHP($command)->toCanonicalExtendedJSON(), [], $event->getDurationMicros() / 1000); } } From fbaeff527cc7b29be034e1a3093e6627cf1d9fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 30 Apr 2025 10:35:20 +0200 Subject: [PATCH 2/2] Test that query time is expressed in milliseconds --- tests/ConnectionTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 75761080e..1f970d819 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -289,6 +289,8 @@ public function testQueryLog() DB::table('items')->get(); $this->assertCount(1, $logs = DB::getQueryLog()); $this->assertJsonStringEqualsJsonString('{"find":"items","filter":{}}', $logs[0]['query']); + $this->assertLessThan(10, $logs[0]['time'], 'Query time is in milliseconds'); + $this->assertGreaterThan(0.01, $logs[0]['time'], 'Query time is in milliseconds'); DB::table('items')->insert(['id' => $id = new ObjectId(), 'name' => 'test']); $this->assertCount(2, $logs = DB::getQueryLog());