Skip to content

Commit

Permalink
[1.x] Cleanup (laravel#356)
Browse files Browse the repository at this point in the history
* Remove TODOs

* Make SQL highlighting configurable at the view layer

* Update upgrade guide

* Formatting

* Include throttle information
  • Loading branch information
timacdonald committed May 1, 2024
1 parent 073e5a6 commit ad5c13d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 24 deletions.
14 changes: 4 additions & 10 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 0 additions & 1 deletion config/pulse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
4 changes: 2 additions & 2 deletions resources/views/livewire/slow-queries.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"',
Expand Down Expand Up @@ -62,7 +62,7 @@
<x-pulse::td class="!p-0 truncate max-w-[1px]">
<div class="relative">
<div class="bg-gray-700 dark:bg-gray-800 py-4 rounded-md text-gray-100 block text-xs whitespace-nowrap overflow-x-auto [scrollbar-color:theme(colors.gray.500)_transparent] [scrollbar-width:thin]">
<code class="px-3">{!! $config['highlighting'] ? $sqlFormatter->highlight($query->sql) : $query->sql !!}</code>
<code class="px-3">{!! $this->disableHighlighting ? $query->sql : $sqlFormatter->highlight($query->sql) !!}</code>
@if ($query->location)
<p class="px-3 mt-3 text-xs leading-none text-gray-400 dark:text-gray-500">
{{ $query->location }}
Expand Down
11 changes: 6 additions & 5 deletions src/Livewire/SlowQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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,
]);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Pulse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions src/Storage/DatabaseStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ad5c13d

Please sign in to comment.