From 0c4a8f764dd76087f7ebde0d372858c4f5938b3e Mon Sep 17 00:00:00 2001 From: "Joseph.Rawlings" Date: Mon, 1 Dec 2025 12:14:10 -0500 Subject: [PATCH] feat: optimize Proxmox statistics loading by preloading data on mount and reducing cache TTL for faster updates --- .../Servers/Proxmox/Livewire/Statistics.php | 7 +++++- .../Proxmox/views/statistics.blade.php | 24 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/extensions/Servers/Proxmox/Livewire/Statistics.php b/extensions/Servers/Proxmox/Livewire/Statistics.php index 32a4a2b65..b103bf4bc 100644 --- a/extensions/Servers/Proxmox/Livewire/Statistics.php +++ b/extensions/Servers/Proxmox/Livewire/Statistics.php @@ -139,6 +139,10 @@ class Statistics extends Component $this->networkAnalysis['topPorts'] = []; $this->networkAnalysis['security'] = []; } + + // Preload graph data on mount to speed up initial display + // This runs in the background while the page is rendering + $this->dispatch('proxmox:stats'); } #[On('proxmox:stats')] @@ -501,7 +505,8 @@ class Statistics extends Component $cacheKey = 'proxmox-stats-' . $this->server->id . '-' . $graphType . '-' . $timeRange . '-' . $aggregation; try { - $data = Cache::remember($cacheKey, 60, function () use ($timeRange, $aggregation) { + // Reduced cache TTL from 60 to 30 seconds for fresher data and faster updates + $data = Cache::remember($cacheKey, 30, function () use ($timeRange, $aggregation) { $proxmox = new Proxmox; $stats = $proxmox->request('/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/rrddata', data: [ 'timeframe' => $timeRange, diff --git a/extensions/Servers/Proxmox/views/statistics.blade.php b/extensions/Servers/Proxmox/views/statistics.blade.php index e8378f860..2e2b9f031 100644 --- a/extensions/Servers/Proxmox/views/statistics.blade.php +++ b/extensions/Servers/Proxmox/views/statistics.blade.php @@ -4341,7 +4341,8 @@ console.warn('Failed to dispatch Proxmox stats event:', e); } - // After a short delay, check if expected charts have received any data. + // After a shorter delay, check if expected charts have received any data. + // Reduced from 3000ms to 800ms for faster loading setTimeout(function () { var allExpectedChartsHaveData = (!cpuChartExpected || cpuChartHasData) && @@ -4362,10 +4363,10 @@ } else { console.warn('Max stats retry attempts reached; some charts may not have data.'); } - }, 3000); + }, 800); } - // Start the retry loop + // Start the retry loop immediately statsRetryAttempts = 0; requestStatsOnce(); } @@ -4440,12 +4441,23 @@ diskChart.render(); } - // After charts are initialized, request stats with a short - // retry loop to ensure data is received even if the first - // request or event is missed. + // Request stats immediately - don't wait for charts to fully render + // This speeds up initial data loading dispatchStatsWithRetry(); }); } + + // Trigger initial stats request as soon as possible, before charts are ready + // This allows backend to start fetching data in parallel with chart initialization + if (typeof Livewire !== 'undefined') { + setTimeout(function() { + try { + Livewire.dispatch('proxmox:stats'); + } catch (e) { + console.warn('Early stats dispatch failed:', e); + } + }, 100); + } // Set up event listeners - these persist across Livewire navigation function setupEventListeners() {