From d36e9e80ee7745185f233335b62467d437cf75ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 22 Mar 2023 19:33:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=B5=81=E9=87=8F=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=B6=E5=90=8C=E6=97=B6=E4=B8=8A=E4=BC=A0=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=89=80=E5=B1=9E=E7=94=A8=E6=88=B7ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/server_daily_stat_dao.go | 27 ++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/internal/db/models/server_daily_stat_dao.go b/internal/db/models/server_daily_stat_dao.go index b173283d..de6a13cb 100644 --- a/internal/db/models/server_daily_stat_dao.go +++ b/internal/db/models/server_daily_stat_dao.go @@ -61,19 +61,24 @@ func (this *ServerDailyStatDAO) SaveStats(tx *dbs.Tx, stats []*pb.ServerDailySta var serverUserMap = map[int64]int64{} // serverId => userId var cacheMap = utils.NewCacheMap() for _, stat := range stats { - day := timeutil.FormatTime("Ymd", stat.CreatedAt) - hour := timeutil.FormatTime("YmdH", stat.CreatedAt) - timeFrom := timeutil.FormatTime("His", stat.CreatedAt) - timeTo := timeutil.FormatTime("His", stat.CreatedAt+5*60-1) // 5分钟 + var day = timeutil.FormatTime("Ymd", stat.CreatedAt) + var hour = timeutil.FormatTime("YmdH", stat.CreatedAt) + var timeFrom = timeutil.FormatTime("His", stat.CreatedAt) + var timeTo = timeutil.FormatTime("His", stat.CreatedAt+5*60-1) // 5分钟 - // 所属用户 - serverUserId, ok := serverUserMap[stat.ServerId] - if !ok { - userId, err := SharedServerDAO.FindServerUserId(tx, stat.ServerId) - if err != nil { - return err + // 用户ID + var serverUserId = stat.UserId + if serverUserId == 0 { + var ok bool + serverUserId, ok = serverUserMap[stat.ServerId] + if !ok { + userId, err := SharedServerDAO.FindServerUserId(tx, stat.ServerId) + if err != nil { + return err + } + serverUserMap[stat.ServerId] = userId + serverUserId = userId } - serverUserId = userId } _, _, err := this.Query(tx).