refactor: streamline data loading process in Statistics and overview views for improved performance
This commit is contained in:
@@ -152,23 +152,25 @@ class Statistics extends Component
|
||||
{
|
||||
parent::mount($server);
|
||||
$this->server->loadMissing('ipAddresses');
|
||||
// Network Analysis is loaded lazily via JavaScript to improve page load speed
|
||||
// Initialize error state if not configured to prevent infinite loading
|
||||
if (!$this->coreRouterEnabled()) {
|
||||
$this->networkAnalysis['error'] = 'Core Router API is not configured.';
|
||||
$this->networkAnalysis['connections'] = [];
|
||||
$this->networkAnalysis['topConnections'] = [];
|
||||
$this->networkAnalysis['topPorts'] = [];
|
||||
$this->networkAnalysis['security'] = [];
|
||||
}
|
||||
|
||||
// Preload graph data on mount to speed up initial display
|
||||
// Dispatch individual chart events for more reliable parallel loading
|
||||
// Each chart loads independently so a failure in one doesn't block others
|
||||
$this->dispatch('proxmox:stats:cpu');
|
||||
$this->dispatch('proxmox:stats:memory');
|
||||
$this->dispatch('proxmox:stats:network');
|
||||
$this->dispatch('proxmox:stats:disk');
|
||||
// Data loading is deferred to loadInitialData() which is triggered via wire:init
|
||||
// This ensures JavaScript charts are fully initialized before data events are dispatched
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all initial data for the statistics page.
|
||||
* Called via wire:init to ensure JavaScript is ready to receive the data.
|
||||
*/
|
||||
public function loadInitialData(): void
|
||||
{
|
||||
// Fetch graph data - each dispatch includes the actual data for JavaScript charts
|
||||
$this->fetchGraphData('cpu', $this->cpuTimeRange, $this->cpuAggregation);
|
||||
$this->fetchGraphData('memory', $this->memoryTimeRange, $this->memoryAggregation);
|
||||
$this->fetchGraphData('network', $this->networkTimeRange, $this->networkAggregation);
|
||||
$this->fetchGraphData('disk', $this->diskTimeRange, $this->diskAggregation);
|
||||
|
||||
// Load Network Analysis
|
||||
$this->loadNetworkAnalysis();
|
||||
}
|
||||
|
||||
#[On('proxmox:stats')]
|
||||
|
||||
Reference in New Issue
Block a user