Skip to content

Commit

Permalink
Use ConditionalQueryWatcher to clean up SlowQueryWatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickomeara committed Jul 26, 2024
1 parent 018728f commit f95af06
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/Watchers/SlowQueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Spatie\LaravelRay\Ray;
use Spatie\Ray\Settings\Settings;

class SlowQueryWatcher extends QueryWatcher
class SlowQueryWatcher extends ConditionalQueryWatcher
{
protected $minimumTimeInMs = 500;

Expand All @@ -19,20 +19,8 @@ public function register(): void
$this->enabled = $settings->send_slow_queries_to_ray ?? false;
$this->minimumTimeInMs = $settings->slow_query_threshold_in_ms ?? $this->minimumTimeInMs;

Event::listen(QueryExecuted::class, function (QueryExecuted $query) {
if (! $this->enabled()) {
return;
}

$ray = app(Ray::class);

if ($query->time >= $this->minimumTimeInMs) {
$payload = new ExecutedQueryPayload($query);

$ray->sendRequest($payload);
}

optional($this->rayProxy)->applyCalledMethods($ray);
$this->setConditionalCallback(function (QueryExecuted $query) {
return $query->time >= $this->minimumTimeInMs;
});
}

Expand Down

0 comments on commit f95af06

Please sign in to comment.