diff --git a/server/websocket/internal/logic/ws_statistics.go b/server/websocket/internal/logic/ws_statistics.go index 5899a613..7d086c1c 100644 --- a/server/websocket/internal/logic/ws_statistics.go +++ b/server/websocket/internal/logic/ws_statistics.go @@ -93,35 +93,42 @@ func ConsumeWebsocketStatData(ctx context.Context) { switch data.Type { case TYPE_CONNECT_COUNT: //ws连接计数 statData, ok := mapUserWsStat.Load(key) - if ok { //存在就累加 - if stat, ok := statData.(mapUserWsStatItem); ok { - stat.CurWsConnectCount += data.Value - if stat.CurWsConnectCount == 0 { //为0则移除 - mapUserWsStat.Delete(key) - } else { - mapUserWsStat.Store(key, stat) - } - } else { - logx.Error("断言mapUserWsStatItem错误") + if !ok { + if data.Value <= 0 { + continue } - } else { //不存在就赋值 mapUserWsStat.Store(key, mapUserWsStatItem{ CurWsConnectCount: data.Value, }) } + stat, ok := statData.(mapUserWsStatItem) + if !ok { + logx.Error("断言mapUserWsStatItem错误") + continue + } + stat.CurWsConnectCount += data.Value + if stat.CurWsConnectCount <= 0 { //小于等于0则移除 + mapUserWsStat.Delete(key) + } else { + mapUserWsStat.Store(key, stat) + } case TYPE_COMBINE_IMAGE_REQUEST_COUNT: //请求算法合图计数 statData, ok := mapUserWsStat.Load(key) - if ok { //存在就累加 - if stat, ok := statData.(mapUserWsStatItem); ok { - stat.CurCombineCount += data.Value - mapUserWsStat.Store(key, stat) - } else { - logx.Error("断言mapUserWsStatItem错误") + if !ok { + if data.Value > 0 { + mapUserWsStat.Store(key, mapUserWsStatItem{ + CurCombineCount: data.Value, + }) } - } else { //不存在就赋值 - mapUserWsStat.Store(key, mapUserWsStatItem{ - CurCombineCount: data.Value, - }) + } + if stat, ok := statData.(mapUserWsStatItem); ok { + stat.CurCombineCount += data.Value + if stat.CurCombineCount < 0 { + stat.CurCombineCount = 0 + } + mapUserWsStat.Store(key, stat) + } else { + logx.Error("断言mapUserWsStatItem错误") } } }