Skip to content

Commit

Permalink
Logging logic for slow queries has been changed. Listen to all querie…
Browse files Browse the repository at this point in the history
…s and log slow queries by individual request time instead of the aggregate time of all queries per request.
  • Loading branch information
dimafe6 committed May 16, 2024
1 parent ccc07bf commit aaea166
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/SlowerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public function packageRegistered(): void
private function registerDatabaseListener(): void
{
if (config('slower.enabled')) {
DB::whenQueryingForLongerThan(config('slower.threshold', 10000), function (Connection $connection, QueryExecuted $event) {
DB::listen(function (QueryExecuted $event) {
if($event->time < config('slower.threshold', 10000)) {
return;
}

if(config('slower.ignore_explain_queries', true) && Str::startsWith($event->sql, 'EXPLAIN')) {
return;
}
Expand All @@ -68,8 +72,8 @@ private function registerDatabaseListener(): void
return;
}

$this->createRecord($event, $connection);
$this->notify($event, $connection);
$this->createRecord($event, $event->connection);
$this->notify($event, $event->connection);
});
}
}
Expand Down

1 comment on commit aaea166

@halilcosdu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimafe6 checking

Please sign in to comment.