zhangzengfei
2024-05-18 90ebf117a7e1ccf630361fe0f66289563b1eeb25
修复设备类型缓存的使用
1个文件已修改
24 ■■■■ 已修改文件
controller/systemCtl.go 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controller/systemCtl.go
@@ -39,10 +39,8 @@
    })
    controller.Auth.PlainTextSecrets = true
    for k, v := range svr.CollectDeviceType() {
        controller.DevCache.Store(k, v)
    }
    controller.DevCache = new(sync.Map)
    controller.InitDeviceCache()
    return controller
}
@@ -80,9 +78,8 @@
        }
    } else {
        // 未缓存的id, 可能是新添加的上下级, 更新缓存
        _, ok := s.DevCache.Load(req.RegisterObject.DeviceID)
        if ok {
            s.ApeRepo.CollectDeviceType()
        if _, ok := s.DevCache.Load(req.RegisterObject.DeviceID); !ok {
            s.InitDeviceCache()
        }
    }
@@ -169,3 +166,16 @@
    c.JSON(http.StatusOK, gin.H{"msg": "ok"})
}
func (s SystemController) InitDeviceCache() {
    // 清空
    s.DevCache.Range(func(key, value interface{}) bool {
        s.DevCache.Delete(key)
        return true
    })
    for k, v := range s.ApeRepo.CollectDeviceType() {
        s.DevCache.Store(k, v)
    }
}