mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-11-04 11:22:10 +08:00 
			
		
		
		
	test
This commit is contained in:
		
							parent
							
								
									3c90d7d552
								
							
						
					
					
						commit
						323c29893f
					
				@ -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)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	go ws.pushUserIDOnlineStatus(ctx, userID, platformIDs)
 | 
						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) {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,16 +1,12 @@
 | 
				
			|||||||
package msggateway
 | 
					package msggateway
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"bytes"
 | 
					 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"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"
 | 
					 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"sync/atomic"
 | 
					 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -35,23 +31,6 @@ type UserPlatform struct {
 | 
				
			|||||||
	Clients []*Client
 | 
						Clients []*Client
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (u *UserPlatform) String() string {
 | 
					 | 
				
			||||||
	buf := bytes.NewBuffer(nil)
 | 
					 | 
				
			||||||
	buf.WriteString("UserPlatform{Time: ")
 | 
					 | 
				
			||||||
	buf.WriteString(u.Time.String())
 | 
					 | 
				
			||||||
	buf.WriteString(", Clients<")
 | 
					 | 
				
			||||||
	buf.WriteString(strconv.Itoa(len(u.Clients)))
 | 
					 | 
				
			||||||
	buf.WriteString(">: [")
 | 
					 | 
				
			||||||
	for i, client := range u.Clients {
 | 
					 | 
				
			||||||
		if i > 0 {
 | 
					 | 
				
			||||||
			buf.WriteString(", ")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		buf.WriteString(fmt.Sprintf("%p %d %s", u.Clients[i], client.PlatformID, constant.PlatformIDToName(client.PlatformID)))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	buf.WriteString("]}")
 | 
					 | 
				
			||||||
	return buf.String()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (u *UserPlatform) PlatformIDs() []int32 {
 | 
					func (u *UserPlatform) PlatformIDs() []int32 {
 | 
				
			||||||
	if len(u.Clients) == 0 {
 | 
						if len(u.Clients) == 0 {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
@ -161,9 +140,6 @@ func (u *userMap) DeleteClients(userID string, clients []*Client) (isDeleteUser
 | 
				
			|||||||
	if len(clients) == 0 {
 | 
						if len(clients) == 0 {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for i, client := range clients {
 | 
					 | 
				
			||||||
		log.ZDebug(context.Background(), "userMap DeleteClients", "userID", userID, "platformID", client.PlatformID, "platform", constant.PlatformIDToName(client.PlatformID), "count", fmt.Sprintf("%p %d/%d", clients[i], i+1, len(clients)))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	u.lock.Lock()
 | 
						u.lock.Lock()
 | 
				
			||||||
	defer u.lock.Unlock()
 | 
						defer u.lock.Unlock()
 | 
				
			||||||
	result, ok := u.data[userID]
 | 
						result, ok := u.data[userID]
 | 
				
			||||||
@ -191,21 +167,12 @@ func (u *userMap) DeleteClients(userID string, clients []*Client) (isDeleteUser
 | 
				
			|||||||
	return true
 | 
						return true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var opIDIncr atomic.Int64
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (u *userMap) GetAllUserStatus(deadline time.Time, nowtime time.Time) (result []UserState) {
 | 
					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 {
 | 
				
			||||||
		skip := deadline.Before(userPlatform.Time)
 | 
							if deadline.Before(userPlatform.Time) {
 | 
				
			||||||
		log.ZDebug(ctx, "userMap GetAllUserStatus", "userID", userID, "skip", skip, "platforms", userPlatform.String())
 | 
					 | 
				
			||||||
		if skip {
 | 
					 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		userPlatform.Time = nowtime
 | 
							userPlatform.Time = nowtime
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										3
									
								
								pkg/common/storage/cache/cachekey/online.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								pkg/common/storage/cache/cachekey/online.go
									
									
									
									
										vendored
									
									
								
							@ -5,8 +5,7 @@ import "time"
 | 
				
			|||||||
const (
 | 
					const (
 | 
				
			||||||
	OnlineKey     = "ONLINE:"
 | 
						OnlineKey     = "ONLINE:"
 | 
				
			||||||
	OnlineChannel = "online_change"
 | 
						OnlineChannel = "online_change"
 | 
				
			||||||
	//OnlineExpire  = time.Hour / 2
 | 
						OnlineExpire  = time.Hour / 2
 | 
				
			||||||
	OnlineExpire = time.Minute / 2 // test
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func GetOnlineKey(userID string) string {
 | 
					func GetOnlineKey(userID string) string {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user