From ceb65cd3914cc7227a82422fce485ded9d30828a Mon Sep 17 00:00:00 2001 From: ljw <84855512@qq.com> Date: Wed, 16 Oct 2024 21:32:55 +0800 Subject: [PATCH] fix write when heartbeat #14 --- http/controller/api/index.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/http/controller/api/index.go b/http/controller/api/index.go index cc06c4c..7f780dd 100644 --- a/http/controller/api/index.go +++ b/http/controller/api/index.go @@ -3,6 +3,7 @@ package api import ( requstform "Gwen/http/request/api" "Gwen/http/response" + "Gwen/model" "Gwen/service" "github.com/gin-gonic/gin" "net/http" @@ -53,7 +54,11 @@ func (i *Index) Heartbeat(c *gin.Context) { c.JSON(http.StatusOK, gin.H{}) return } - peer.LastOnlineTime = time.Now().Unix() - service.AllService.PeerService.Update(peer) + //如果在一分钟以内则不更新 + if time.Now().Unix()-peer.LastOnlineTime > 60 { + peer.LastOnlineTime = time.Now().Unix() + upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: peer.LastOnlineTime} + service.AllService.PeerService.Update(upp) + } c.JSON(http.StatusOK, gin.H{}) }