From 90ebf117a7e1ccf630361fe0f66289563b1eeb25 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期六, 18 五月 2024 11:48:43 +0800
Subject: [PATCH] 修复设备类型缓存的使用

---
 controller/systemCtl.go |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/controller/systemCtl.go b/controller/systemCtl.go
index 0dc7cd4..e098524 100644
--- a/controller/systemCtl.go
+++ b/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)
+	}
+
+}

--
Gitblit v1.8.0