mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 03:42:08 +08:00
test
This commit is contained in:
parent
5fb43eacac
commit
389b05dc44
@ -107,7 +107,7 @@ func (ws *WsServer) ChangeOnlineStatus(concurrent int) {
|
|||||||
case now := <-renewalTicker.C:
|
case now := <-renewalTicker.C:
|
||||||
deadline := now.Add(-cachekey.OnlineExpire / 3)
|
deadline := now.Add(-cachekey.OnlineExpire / 3)
|
||||||
users := ws.clients.GetAllUserStatus(deadline, now)
|
users := ws.clients.GetAllUserStatus(deadline, now)
|
||||||
log.ZDebug(context.Background(), "renewal ticker", "deadline", deadline, "nowtime", now, "users", users)
|
log.ZDebug(context.Background(), "renewal ticker", "deadline", deadline, "nowtime", now, "num", len(users), "users", users)
|
||||||
pushUserState(users...)
|
pushUserState(users...)
|
||||||
case state := <-ws.clients.UserState():
|
case state := <-ws.clients.UserState():
|
||||||
log.ZDebug(context.Background(), "OnlineCache user online change", "userID", state.UserID, "online", state.Online, "offline", state.Offline)
|
log.ZDebug(context.Background(), "OnlineCache user online change", "userID", state.UserID, "online", state.Online, "offline", state.Offline)
|
||||||
|
|||||||
@ -15,7 +15,7 @@ func (ws *WsServer) subscriberUserOnlineStatusChanges(ctx context.Context, userI
|
|||||||
} else {
|
} else {
|
||||||
log.ZDebug(ctx, "gateway ignore user online status changes", "userID", userID, "platformIDs", platformIDs)
|
log.ZDebug(ctx, "gateway ignore user online status changes", "userID", userID, "platformIDs", platformIDs)
|
||||||
}
|
}
|
||||||
ws.pushUserIDOnlineStatus(ctx, userID, platformIDs)
|
go ws.pushUserIDOnlineStatus(ctx, userID, platformIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *WsServer) SubUserOnlineStatus(ctx context.Context, client *Client, data *Req) ([]byte, error) {
|
func (ws *WsServer) SubUserOnlineStatus(ctx context.Context, client *Client, data *Req) ([]byte, error) {
|
||||||
|
|||||||
@ -6,9 +6,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
"github.com/openimsdk/tools/log"
|
"github.com/openimsdk/tools/log"
|
||||||
|
"github.com/openimsdk/tools/mcontext"
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,7 +38,7 @@ type UserPlatform struct {
|
|||||||
func (u *UserPlatform) String() string {
|
func (u *UserPlatform) String() string {
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
buf.WriteString("UserPlatform{Time: ")
|
buf.WriteString("UserPlatform{Time: ")
|
||||||
buf.WriteString(u.Time.Format(time.DateTime))
|
buf.WriteString(u.Time.String())
|
||||||
buf.WriteString(", Clients<")
|
buf.WriteString(", Clients<")
|
||||||
buf.WriteString(strconv.Itoa(len(u.Clients)))
|
buf.WriteString(strconv.Itoa(len(u.Clients)))
|
||||||
buf.WriteString(">: [")
|
buf.WriteString(">: [")
|
||||||
@ -189,13 +191,21 @@ func (u *userMap) DeleteClients(userID string, clients []*Client) (isDeleteUser
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userMap) GetAllUserStatus(deadline time.Time, nowtime time.Time) []UserState {
|
var opIDIncr atomic.Int64
|
||||||
|
|
||||||
|
func (u *userMap) GetAllUserStatus(deadline time.Time, nowtime time.Time) (result []UserState) {
|
||||||
|
ctx := mcontext.SetOperationID(context.Background(), fmt.Sprintf("op_%d", opIDIncr.Add(1)))
|
||||||
|
log.ZDebug(ctx, "userMap GetAllUserStatus", "deadline", deadline, "nowtime", nowtime)
|
||||||
|
defer func() {
|
||||||
|
log.ZDebug(ctx, "userMap GetAllUserStatus", "num", len(result), "result", result)
|
||||||
|
}()
|
||||||
u.lock.RLock()
|
u.lock.RLock()
|
||||||
defer u.lock.RUnlock()
|
defer u.lock.RUnlock()
|
||||||
result := make([]UserState, 0, len(u.data))
|
result = make([]UserState, 0, len(u.data))
|
||||||
for userID, userPlatform := range u.data {
|
for userID, userPlatform := range u.data {
|
||||||
log.ZDebug(context.Background(), "userMap GetAllUserStatus", "userID", userID, "platforms", userPlatform.String())
|
add := userPlatform.Time.Before(deadline)
|
||||||
if userPlatform.Time.Before(deadline) {
|
log.ZDebug(ctx, "userMap GetAllUserStatus", "userID", userID, "add", add, "platforms", userPlatform.String())
|
||||||
|
if add {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
userPlatform.Time = nowtime
|
userPlatform.Time = nowtime
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user