feat: optimize Proxmox statistics loading by preloading data on mount and reducing cache TTL for faster updates
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user