|
|
@ -155,51 +155,50 @@ func (o *OnlineCache) GetUserOnline(ctx context.Context, userID string) (bool, e
|
|
|
|
return len(platformIDs) > 0, nil
|
|
|
|
return len(platformIDs) > 0, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (o *OnlineCache) getUserOnlinePlatformBatch(ctx context.Context, userIDs []string) (map[string][]int32, error) {
|
|
|
|
//func (o *OnlineCache) getUserOnlinePlatformBatch(ctx context.Context, userIDs []string) (map[string][]int32, error) {
|
|
|
|
platformIDsMap, err := o.lruCache.GetBatch(userIDs, func(missingUsers []string) (map[string][]int32, error) {
|
|
|
|
// platformIDsMap, err := o.lruCache.GetBatch(userIDs, func(missingUsers []string) (map[string][]int32, error) {
|
|
|
|
platformIDsMap := make(map[string][]int32)
|
|
|
|
// platformIDsMap := make(map[string][]int32)
|
|
|
|
|
|
|
|
//
|
|
|
|
usersStatus, err := o.user.GetUsersOnlinePlatform(ctx, missingUsers)
|
|
|
|
// usersStatus, err := o.user.GetUsersOnlinePlatform(ctx, missingUsers)
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
return nil, err
|
|
|
|
// return nil, err
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
for _, user := range usersStatus {
|
|
|
|
// for _, user := range usersStatus {
|
|
|
|
platformIDsMap[user.UserID] = user.PlatformIDs
|
|
|
|
// platformIDsMap[user.UserID] = user.PlatformIDs
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
return platformIDsMap, nil
|
|
|
|
// return platformIDsMap, nil
|
|
|
|
})
|
|
|
|
// })
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
log.ZError(ctx, "OnlineCache GetUserOnlinePlatform", err, "userID", userIDs)
|
|
|
|
// log.ZError(ctx, "OnlineCache GetUserOnlinePlatform", err, "userID", userIDs)
|
|
|
|
return nil, err
|
|
|
|
// return nil, err
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
//log.ZDebug(ctx, "OnlineCache GetUserOnlinePlatform", "userID", userID, "platformIDs", platformIDs)
|
|
|
|
// //log.ZDebug(ctx, "OnlineCache GetUserOnlinePlatform", "userID", userID, "platformIDs", platformIDs)
|
|
|
|
return platformIDsMap, nil
|
|
|
|
// return platformIDsMap, nil
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (o *OnlineCache) GetUsersOnline(ctx context.Context, usersID []string) ([]string, []string, error) {
|
|
|
|
func (o *OnlineCache) GetUsersOnline(ctx context.Context, userIDs []string) ([]string, []string, error) {
|
|
|
|
t := time.Now()
|
|
|
|
t := time.Now()
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
onlineUserIDs []string
|
|
|
|
onlineUserIDs = make([]string, 0, len(userIDs))
|
|
|
|
offlineUserIDs []string
|
|
|
|
offlineUserIDs = make([]string, 0, len(userIDs))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
//
|
|
|
|
userOnlineMap, err := o.getUserOnlinePlatformBatch(ctx, userIDs)
|
|
|
|
//userOnlineMap, err := o.getUserOnlinePlatformBatch(ctx, userIDs)
|
|
|
|
if err != nil {
|
|
|
|
//if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
// return nil, nil, err
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
//
|
|
|
|
for key, value := range userOnlineMap {
|
|
|
|
//for key, value := range userOnlineMap {
|
|
|
|
if len(value) > 0 {
|
|
|
|
// if len(value) > 0 {
|
|
|
|
onlineUserIDs = append(onlineUserIDs, key)
|
|
|
|
// onlineUserIDs = append(onlineUserIDs, key)
|
|
|
|
} else {
|
|
|
|
// } else {
|
|
|
|
offlineUserIDs = append(offlineUserIDs, key)
|
|
|
|
// offlineUserIDs = append(offlineUserIDs, key)
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
switch o.fullUserCache {
|
|
|
|
switch o.fullUserCache {
|
|
|
|
case true:
|
|
|
|
case true:
|
|
|
@ -213,8 +212,8 @@ func (o *OnlineCache) GetUsersOnline(ctx context.Context, usersID []string) ([]s
|
|
|
|
case false:
|
|
|
|
case false:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.ZWarn(ctx, "get users online", nil, "online users length", len(onlineUserIDS), "offline users length", len(offlineUserIDs), "cost", time.Since(t))
|
|
|
|
log.ZWarn(ctx, "get users online", nil, "online users length", len(userIDs), "offline users length", len(offlineUserIDs), "cost", time.Since(t))
|
|
|
|
return onlineUserIDS, offlineUserIDs, nil
|
|
|
|
return userIDs, offlineUserIDs, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//func (o *OnlineCache) GetUsersOnline(ctx context.Context, userIDs []string) ([]string, error) {
|
|
|
|
//func (o *OnlineCache) GetUsersOnline(ctx context.Context, userIDs []string) ([]string, error) {
|
|
|
|