fix
This commit is contained in:
parent
b12a61b2f6
commit
a6a01dae3d
|
@ -16,12 +16,11 @@ const (
|
|||
TYPE_CUR_UNITY_HANDLE_COUNT websocketStatType = "TYPE_CUR_UNITY_HANDLE_COUNT" //unity处理数
|
||||
)
|
||||
|
||||
type websocketStatItem struct {
|
||||
UserId int64 `json:"user_id"`
|
||||
GuestId int64 `json:"guest_id"`
|
||||
Type websocketStatType `json:"type"` //类型
|
||||
Value int `json:"value"` //数值
|
||||
UnityRenderLogId int64 `json:"unity_render_log_id"` //unity渲染的日志id
|
||||
type websocketStatData struct {
|
||||
UserId int64 `json:"user_id"` //用户id
|
||||
GuestId int64 `json:"guest_id"` //游客id
|
||||
Type websocketStatType `json:"type"` //类型
|
||||
Num int `json:"num"` //数值
|
||||
}
|
||||
type mapUserWsStatItem struct {
|
||||
CurCombineCount int `json:"cur_combine_count"` //当前合图数
|
||||
|
@ -34,16 +33,16 @@ var (
|
|||
//用户连接统计
|
||||
mapUserWsStat = sync.Map{}
|
||||
//添加or减少连接的控制chan
|
||||
websocketStat = make(chan websocketStatItem, 1000)
|
||||
websocketStat = make(chan websocketStatData, 1000)
|
||||
)
|
||||
|
||||
// 累增ws连接数计数
|
||||
func increaseWebsocketConnectCount(userId, guestId int64) {
|
||||
data := websocketStatItem{
|
||||
data := websocketStatData{
|
||||
UserId: userId,
|
||||
GuestId: guestId,
|
||||
Type: TYPE_CUR_CONNECT_COUNT,
|
||||
Value: 1,
|
||||
Num: 1,
|
||||
}
|
||||
select {
|
||||
case websocketStat <- data:
|
||||
|
@ -56,11 +55,11 @@ func increaseWebsocketConnectCount(userId, guestId int64) {
|
|||
|
||||
// 减少ws连接数计数
|
||||
func decreaseWebsocketConnectCount(userId, guestId int64) {
|
||||
data := websocketStatItem{
|
||||
data := websocketStatData{
|
||||
UserId: userId,
|
||||
GuestId: guestId,
|
||||
Type: TYPE_CUR_CONNECT_COUNT,
|
||||
Value: -1,
|
||||
Num: -1,
|
||||
}
|
||||
select {
|
||||
case websocketStat <- data:
|
||||
|
@ -73,11 +72,11 @@ func decreaseWebsocketConnectCount(userId, guestId int64) {
|
|||
|
||||
// 累增合图请求数计数
|
||||
func increaseCombineRequestCount(userId, guestId int64) {
|
||||
data := websocketStatItem{
|
||||
data := websocketStatData{
|
||||
UserId: userId,
|
||||
GuestId: guestId,
|
||||
Type: TYPE_CUR_COMBINE_IMAGE_COUNT,
|
||||
Value: 1,
|
||||
Num: 1,
|
||||
}
|
||||
select {
|
||||
case websocketStat <- data:
|
||||
|
@ -90,11 +89,11 @@ func increaseCombineRequestCount(userId, guestId int64) {
|
|||
|
||||
// 减少合图请求数计数
|
||||
func decreaseCombineRequestCount(userId, guestId int64) {
|
||||
data := websocketStatItem{
|
||||
data := websocketStatData{
|
||||
UserId: userId,
|
||||
GuestId: guestId,
|
||||
Type: TYPE_CUR_COMBINE_IMAGE_COUNT,
|
||||
Value: -1,
|
||||
Num: -1,
|
||||
}
|
||||
select {
|
||||
case websocketStat <- data:
|
||||
|
@ -107,11 +106,11 @@ func decreaseCombineRequestCount(userId, guestId int64) {
|
|||
|
||||
// 累增unity请求数计数
|
||||
func increaseUnityRequestCount(userId, guestId int64) {
|
||||
data := websocketStatItem{
|
||||
data := websocketStatData{
|
||||
UserId: userId,
|
||||
GuestId: guestId,
|
||||
Type: TYPE_CUR_UNITY_HANDLE_COUNT,
|
||||
Value: 1,
|
||||
Num: 1,
|
||||
}
|
||||
select {
|
||||
case websocketStat <- data:
|
||||
|
@ -124,11 +123,11 @@ func increaseUnityRequestCount(userId, guestId int64) {
|
|||
|
||||
// 减少unity请求数计数
|
||||
func decreaseUnityRequestCount(userId, guestId int64) {
|
||||
data := websocketStatItem{
|
||||
data := websocketStatData{
|
||||
UserId: userId,
|
||||
GuestId: guestId,
|
||||
Type: TYPE_CUR_UNITY_HANDLE_COUNT,
|
||||
Value: -1,
|
||||
Num: -1,
|
||||
}
|
||||
select {
|
||||
case websocketStat <- data:
|
||||
|
@ -161,7 +160,7 @@ func ConsumeWebsocketStatData(ctx context.Context) {
|
|||
case TYPE_CUR_CONNECT_COUNT: //ws连接计数
|
||||
if !ok {
|
||||
mapUserWsStat.Store(key, mapUserWsStatItem{
|
||||
CurWsConnectCount: data.Value,
|
||||
CurWsConnectCount: data.Num,
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
@ -170,7 +169,7 @@ func ConsumeWebsocketStatData(ctx context.Context) {
|
|||
logx.Error("断言mapUserWsStatItem错误")
|
||||
continue
|
||||
}
|
||||
stat.CurWsConnectCount += data.Value
|
||||
stat.CurWsConnectCount += data.Num
|
||||
//没有连接就删除
|
||||
if stat.CurWsConnectCount <= 0 {
|
||||
mapUserWsStat.Delete(key)
|
||||
|
@ -189,7 +188,7 @@ func ConsumeWebsocketStatData(ctx context.Context) {
|
|||
logx.Error("断言mapUserWsStatItem错误")
|
||||
continue
|
||||
}
|
||||
stat.CurCombineCount += data.Value
|
||||
stat.CurCombineCount += data.Num
|
||||
if stat.CurCombineCount < 0 {
|
||||
stat.CurCombineCount = 0
|
||||
}
|
||||
|
@ -205,7 +204,7 @@ func ConsumeWebsocketStatData(ctx context.Context) {
|
|||
logx.Error("断言mapUserWsStatItem错误")
|
||||
continue
|
||||
}
|
||||
stat.CurUnityHandleCount += data.Value
|
||||
stat.CurUnityHandleCount += data.Num
|
||||
if stat.CurUnityHandleCount <= 0 {
|
||||
stat.CurUnityHandleCount = 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user