From 9d6481d0db11a3d4a10edb5adf30c687a3ad3e3b Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Tue, 30 Apr 2024 17:09:22 +1000 Subject: [PATCH] [1.x] Cleanup (#356) * Remove TODOs * Make SQL highlighting configurable at the view layer * Update upgrade guide * Formatting * Include throttle information --- UPGRADE.md | 14 ++++---------- config/pulse.php | 1 - resources/views/livewire/slow-queries.blade.php | 4 ++-- src/Livewire/SlowQueries.php | 11 ++++++----- src/Pulse.php | 2 -- src/Storage/DatabaseStorage.php | 4 ---- 6 files changed, 12 insertions(+), 24 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index b06968ad..15e1c419 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,14 +2,8 @@ # Beta to 1.x -## Required - -- [Added a `pulse.recorders.SlowQueries.highlight` configuration option](https://github.com/laravel/pulse/pull/172). You should update your configuration to match. -- [`pulse.ingest.trim_lottery` configuration key was renamed to `pulse.ingest.trim.lottery`](https://github.com/laravel/pulse/pull/184). You should update your configuration to match. -- [Added a `pulse.ingest.trim.keep` configuration option](https://github.com/laravel/pulse/pull/184). You should update your configuration to match. - -## Optional - +- [SQL highlighting configuration was moved to the dashboard component](https://github.com/laravel/pulse/pull/356). This is required if you are disabling SQL highlighting. - [Auto-incrementing IDs were added to Pulse's tables](https://github.com/laravel/pulse/pull/142). This is recommended if you are using a configuration that requires tables to have a unique key on every table, e.g., PlanetScale. -- [The TEXT columns were made MEDIUMTEXT columns in the `pulse_` tables](https://github.com/laravel/pulse/pull/185). Recommend to support longer content values, such as long SQL queries. -- [Pulse's migrations are now published to the application](https://github.com/laravel/pulse/pull/81). Recommend so you can have complete control over the migrations as needed. +- [The TEXT columns were made MEDIUMTEXT columns in the `pulse_` tables](https://github.com/laravel/pulse/pull/185). This is recommend to support longer content values, such as long SQL queries. +- [Pulse's migrations are now published to the application](https://github.com/laravel/pulse/pull/81). This is recommend so you can have complete control over the migrations as needed. +- [`pulse:check` now dispatches events roughly every second](https://github.com/laravel/pulse/pull/314). It is recommended to use the new `throttle` function when performing work on specific intervals. diff --git a/config/pulse.php b/config/pulse.php index fdb2f2aa..e417066d 100644 --- a/config/pulse.php +++ b/config/pulse.php @@ -195,7 +195,6 @@ 'sample_rate' => env('PULSE_SLOW_QUERIES_SAMPLE_RATE', 1), 'threshold' => env('PULSE_SLOW_QUERIES_THRESHOLD', 1000), 'location' => env('PULSE_SLOW_QUERIES_LOCATION', true), - 'highlighting' => env('PULSE_SLOW_QUERIES_HIGHLIGHTING', true), 'max_query_length' => env('PULSE_SLOW_QUERIES_MAX_QUERY_LENGTH', null), 'ignore' => [ '/(["`])pulse_[\w]+?\1/', // Pulse tables... diff --git a/resources/views/livewire/slow-queries.blade.php b/resources/views/livewire/slow-queries.blade.php index b157a570..fba7a72e 100644 --- a/resources/views/livewire/slow-queries.blade.php +++ b/resources/views/livewire/slow-queries.blade.php @@ -2,7 +2,7 @@ use \Doctrine\SqlFormatter\HtmlHighlighter; use \Doctrine\SqlFormatter\SqlFormatter; -if ($config['highlighting']) { +if (! $this->disableHighlighting) { $sqlFormatter = new SqlFormatter(new HtmlHighlighter([ HtmlHighlighter::HIGHLIGHT_RESERVED => 'class="font-semibold"', HtmlHighlighter::HIGHLIGHT_QUOTE => 'class="text-purple-200"', @@ -62,7 +62,7 @@
- {!! $config['highlighting'] ? $sqlFormatter->highlight($query->sql) : $query->sql !!} + {!! $this->disableHighlighting ? $query->sql : $sqlFormatter->highlight($query->sql) !!} @if ($query->location)

{{ $query->location }} diff --git a/src/Livewire/SlowQueries.php b/src/Livewire/SlowQueries.php index 51029551..39df62ea 100644 --- a/src/Livewire/SlowQueries.php +++ b/src/Livewire/SlowQueries.php @@ -23,6 +23,11 @@ class SlowQueries extends Card #[Url(as: 'slow-queries')] public string $orderBy = 'slowest'; + /** + * Indicates that SQL highlighting should be disabled. + */ + public bool $disableHighlighting = false; + /** * Render the component. */ @@ -52,11 +57,7 @@ public function render(): Renderable return View::make('pulse::livewire.slow-queries', [ 'time' => $time, 'runAt' => $runAt, - 'config' => [ - // TODO remove fallback when tagging v1 - 'highlighting' => true, - ...Config::get('pulse.recorders.'.SlowQueriesRecorder::class), - ], + 'config' => Config::get('pulse.recorders.'.SlowQueriesRecorder::class), 'slowQueries' => $slowQueries, ]); } diff --git a/src/Pulse.php b/src/Pulse.php index a3e14fee..f4679ea8 100644 --- a/src/Pulse.php +++ b/src/Pulse.php @@ -307,7 +307,6 @@ public function ingest(): int return $entries->count(); }) ?? 0; - // TODO remove fallback when tagging v1 $odds = $this->app->make('config')->get('pulse.ingest.trim.lottery') ?? $this->app->make('config')->get('pulse.ingest.trim_lottery'); Lottery::odds(...$odds) @@ -350,7 +349,6 @@ protected function ingestWhenOverBufferSize(): void return; } - // TODO remove fallback when tagging v1 $buffer = $this->app->make('config')->get('pulse.ingest.buffer') ?? 5_000; if (($this->entries->count() + $this->lazy->count()) > $buffer) { diff --git a/src/Storage/DatabaseStorage.php b/src/Storage/DatabaseStorage.php index 995c6d08..6274cc6f 100644 --- a/src/Storage/DatabaseStorage.php +++ b/src/Storage/DatabaseStorage.php @@ -135,10 +135,6 @@ public function trim(): void ->where('timestamp', '<=', $now->subWeek()->getTimestamp()) ->delete(); - // TODO: Run a single delete with multiple grouped conditions? - // E.g. where (`period` = 60 AND `bucket` <= 1623072000) or (`period` = 360 AND `bucket` <= 1623046800) - // 1 query instead of 5 - $this->connection() ->table('pulse_aggregates') ->distinct()