fix(dashboard): не обнулять узлы кластера при REST-рефетче и сбоях WS
Данные по узлам (nodes) приходят только из WebSocket dashboard_metrics, а REST /api/resources/all их не содержит. Каждый 15-секундный рефетч REST затирал ноды -> таблица узлов и счётчик обнулялись, WS возвращал через 2с. - frontend: при REST-рефетче переносим последние известные nodes из кэша, чтобы node-таблица не мигала - backend: кэш последнего удачного опроса по каждому серверу (_server_last_good) — транзиентный таймаут Proxmox больше не отдаёт пустые vms/containers/nodes Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -370,7 +370,22 @@ export default function DashboardPage() {
|
||||
|
||||
const { data: resources } = useQuery({
|
||||
queryKey: ['resources'],
|
||||
queryFn: () => apiClient.get<Rec>('/proxmox/api/resources/all'),
|
||||
queryFn: async () => {
|
||||
const fresh = await apiClient.get<Rec>('/proxmox/api/resources/all')
|
||||
// The REST endpoint returns VMs/containers but NOT per-node stats — those
|
||||
// arrive only via the dashboard_metrics WebSocket. Graft the last known
|
||||
// nodes so this 15 s refetch doesn't blank the node table each cycle.
|
||||
const prev = qc.getQueryData<Rec>(['resources'])
|
||||
const prevServers = (prev?.servers as Rec[]) ?? []
|
||||
if (prevServers.length) {
|
||||
const nodesById = new Map(prevServers.map(s => [s.id, s.nodes]))
|
||||
const servers = ((fresh.servers as Rec[]) ?? []).map(s =>
|
||||
(s.nodes as Rec[])?.length ? s : { ...s, nodes: nodesById.get(s.id) ?? [] }
|
||||
)
|
||||
return { ...fresh, servers }
|
||||
}
|
||||
return fresh
|
||||
},
|
||||
refetchInterval: 15000,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user