fix(dashboard): не обнулять узлы кластера при REST-рефетче и сбоях WS
Some checks failed
Backend Tests / pytest (Python 3.12) (push) Successful in 56s
Deploy to Production / Trigger production update (push) Failing after 9s

Данные по узлам (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:
markmorado
2026-07-05 00:56:08 +05:00
parent d4c5c6110a
commit b9e5ef9426
2 changed files with 43 additions and 4 deletions

View File

@@ -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,
})