fix(control): 视频源统计更新到 registry 当前设备对象

discovery 每轮会替换设备指针,graph 轮询更新旧指针导致
UI 拿到新指针(统计恒 0)。改为按 device_id 更新 registry
中当前对象。
This commit is contained in:
tian 2026-08-02 12:26:05 +08:00
parent db7284d2e5
commit a906113221

View File

@ -96,17 +96,23 @@ func (s *RegistryService) startGraphPolling() {
for _, dev := range onlineDevices {
data, _, err := s.agent.Do("GET", dev.IP, dev.AgentPort, "/v1/graphs", nil)
if err == nil {
var graphs interface{}
if err := json.Unmarshal(data, &graphs); err == nil {
s.mu.Lock()
dev.Graphs = graphs
total, online, down := parseVideoSourceStats(graphs)
dev.VideoSourceTotal, dev.VideoSourceOnline, dev.VideoSourceDown = total, online, down
s.mu.Unlock()
s.persistDevice(dev)
}
if err != nil {
continue
}
var graphs interface{}
if err := json.Unmarshal(data, &graphs); err != nil {
continue
}
total, online, down := parseVideoSourceStats(graphs)
s.mu.Lock()
// discovery 可能已替换设备指针,更新 registry 中当前对象
if cur, ok := s.devices[dev.DeviceID]; ok {
cur.Graphs = graphs
cur.VideoSourceTotal = total
cur.VideoSourceOnline = online
cur.VideoSourceDown = down
}
s.mu.Unlock()
}
}
}