From dc427359870f641665788ed2cf775d694272792e Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期三, 22 五月 2024 02:04:00 +0800
Subject: [PATCH] 减少设备订阅上报的频率

---
 service/subscribe.go |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/service/subscribe.go b/service/subscribe.go
index 0a6ce89..e00f151 100644
--- a/service/subscribe.go
+++ b/service/subscribe.go
@@ -109,10 +109,11 @@
 }
 
 type SubscribeTask struct {
-	ctx      context.Context
-	conf     *models.Subscribe
-	faceList []*vo.FaceObject
-	mutex    sync.Mutex
+	ctx          context.Context
+	conf         *models.Subscribe
+	faceList     []*vo.FaceObject
+	mutex        sync.Mutex
+	lastExecTime int64
 }
 
 func (task *SubscribeTask) Start() {
@@ -150,6 +151,11 @@
 
 		// 涓婃姤璁惧
 		if subType == vo.SubscribeApe {
+			// 璁惧閫氱煡鎺у埗棰戠巼, 閬垮厤棰戠箒, 涓婄骇涓�鑸細涓嬪彂绉掔骇鐨勪换鍔�, 浣嗚澶囦笉浼氶绻佹洿鏂�,
+			if time.Now().Unix()-task.lastExecTime < 60*10 {
+				continue
+			}
+
 			var notification = vo.DeviceNotification{
 				NotificationID:   triggerTime + snowflake.GenerateIdStr(),
 				SubscribeID:      task.conf.Id,
@@ -218,4 +224,6 @@
 			client.Notify(task.conf.Ext.ReceiveAddr, b)
 		}
 	}
+
+	task.lastExecTime = time.Now().Unix()
 }

--
Gitblit v1.8.0