From 5d10a5268dd0ff2a570356e9b3cec30bd3b28248 Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Fri, 6 Oct 2023 12:23:57 +1000 Subject: [PATCH] Cache servers data and show stats --- resources/views/livewire/servers.blade.php | 2 +- src/Livewire/Servers.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/resources/views/livewire/servers.blade.php b/resources/views/livewire/servers.blade.php index 51ec41d4..42910937 100644 --- a/resources/views/livewire/servers.blade.php +++ b/resources/views/livewire/servers.blade.php @@ -50,7 +50,7 @@ class="overflow-x-auto pb-px default:col-span-full default:lg:col-span-{{ $cols
- {{ $server->name }} + {{ $server->name }}
diff --git a/src/Livewire/Servers.php b/src/Livewire/Servers.php index 4d3c513f..fe8424e3 100644 --- a/src/Livewire/Servers.php +++ b/src/Livewire/Servers.php @@ -5,20 +5,21 @@ use Illuminate\Contracts\Support\Renderable; use Illuminate\Support\Facades\View; use Laravel\Pulse\Livewire\Concerns\HasPeriod; +use Laravel\Pulse\Livewire\Concerns\RemembersQueries; use Laravel\Pulse\Livewire\Concerns\ShouldNotReportUsage; use Livewire\Attributes\Lazy; #[Lazy] class Servers extends Card { - use HasPeriod, ShouldNotReportUsage; + use HasPeriod, RemembersQueries, ShouldNotReportUsage; /** * Render the component. */ public function render(callable $query): Renderable { - $servers = $query($this->periodAsInterval()); + [$servers, $time, $runAt] = $this->remember($query); if (request()->hasHeader('X-Livewire')) { $this->dispatch('chart-update', servers: $servers); @@ -26,6 +27,8 @@ public function render(callable $query): Renderable return View::make('pulse::livewire.servers', [ 'servers' => $servers, + 'time' => $time, + 'runAt' => $runAt, ]); }