pull/232/head
wangchuxiao 3 years ago
parent 8240cb9c0f
commit 0460033281

@ -11,11 +11,11 @@ import (
commonPb "Open_IM/pkg/proto/sdk_ws" commonPb "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"context" "context"
"google.golang.org/grpc"
"net" "net"
"strconv" "strconv"
"strings" "strings"
"sync"
"google.golang.org/grpc"
) )
type cacheServer struct { type cacheServer struct {
@ -103,27 +103,33 @@ func SyncDB2Cache() error {
func DelRelationCache() {} func DelRelationCache() {}
func updateAllUserToCache(userList []db.User) error { func updateAllUserToCache(userList []db.User) error {
wg := &sync.WaitGroup{}
wg.Add(len(userList))
for _, userInfo := range userList { for _, userInfo := range userList {
userInfoPb := &commonPb.UserInfo{ go func() {
UserID: userInfo.UserID, defer wg.Done()
Nickname: userInfo.Nickname, userInfoPb := &commonPb.UserInfo{
FaceURL: userInfo.FaceURL, UserID: userInfo.UserID,
Gender: userInfo.Gender, Nickname: userInfo.Nickname,
PhoneNumber: userInfo.PhoneNumber, FaceURL: userInfo.FaceURL,
Birth: uint32(userInfo.Birth.Unix()), Gender: userInfo.Gender,
Email: userInfo.Email, PhoneNumber: userInfo.PhoneNumber,
Ex: userInfo.Ex, Birth: uint32(userInfo.Birth.Unix()),
CreateTime: uint32(userInfo.CreateTime.Unix()), Email: userInfo.Email,
AppMangerLevel: userInfo.AppMangerLevel, Ex: userInfo.Ex,
} CreateTime: uint32(userInfo.CreateTime.Unix()),
m, err := utils.Pb2Map(userInfoPb) AppMangerLevel: userInfo.AppMangerLevel,
if err != nil { }
log.NewWarn("", utils.GetSelfFuncName(), err.Error()) m, err := utils.Pb2Map(userInfoPb)
} if err != nil {
if err := db.DB.SetUserInfoToCache(userInfo.UserID, m); err != nil { log.NewWarn("", utils.GetSelfFuncName(), err.Error())
log.NewWarn("0", utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error()) }
} if err := db.DB.SetUserInfoToCache(userInfo.UserID, m); err != nil {
log.NewWarn("0", utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error())
}
}()
} }
wg.Wait()
log.NewInfo("0", utils.GetSelfFuncName(), "ok") log.NewInfo("0", utils.GetSelfFuncName(), "ok")
return nil return nil
} }
@ -135,55 +141,73 @@ func updateAllGroupMemberListToCache() error {
log.NewWarn("0", utils.GetSelfFuncName(), "getAllGroupIDList failed", err.Error()) log.NewWarn("0", utils.GetSelfFuncName(), "getAllGroupIDList failed", err.Error())
panic(err.Error()) panic(err.Error())
} }
wg := &sync.WaitGroup{}
wg.Add(len(groupIDList))
for _, groupID := range groupIDList { for _, groupID := range groupIDList {
groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID) go func() {
if err != nil { defer wg.Done()
log.NewWarn("", utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID", err.Error()) groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID)
continue if err != nil {
} log.NewWarn("", utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID", err.Error())
//log.NewDebug("", utils.GetSelfFuncName(), "groupMemberIDList", groupMemberIDList) return
if len(groupMemberIDList) > 0 {
if err := db.DB.AddGroupMemberToCache(groupID, groupMemberIDList...); err != nil {
log.NewWarn("", utils.GetSelfFuncName(), "AddGroupMemberToCache", err.Error())
} }
} //log.NewDebug("", utils.GetSelfFuncName(), "groupMemberIDList", groupMemberIDList)
if len(groupMemberIDList) > 0 {
if err := db.DB.AddGroupMemberToCache(groupID, groupMemberIDList...); err != nil {
log.NewWarn("", utils.GetSelfFuncName(), "AddGroupMemberToCache", err.Error())
}
}
}()
} }
wg.Wait()
log.NewInfo("0", utils.GetSelfFuncName(), "ok") log.NewInfo("0", utils.GetSelfFuncName(), "ok")
return nil return nil
} }
func updateAllFriendToCache(userList []db.User) error { func updateAllFriendToCache(userList []db.User) error {
log.NewInfo("0", utils.GetSelfFuncName()) log.NewInfo("0", utils.GetSelfFuncName())
wg := sync.WaitGroup{}
wg.Add(len(userList))
for _, user := range userList { for _, user := range userList {
friendIDList, err := imdb.GetFriendIDListByUserID(user.UserID) go func() {
if err != nil { defer wg.Done()
log.NewWarn("0", utils.GetSelfFuncName(), err.Error()) friendIDList, err := imdb.GetFriendIDListByUserID(user.UserID)
continue if err != nil {
} log.NewWarn("0", utils.GetSelfFuncName(), err.Error())
if len(friendIDList) > 0 { return
if err := db.DB.AddFriendToCache(user.UserID, friendIDList...); err != nil {
log.NewWarn("0", utils.GetSelfFuncName(), err.Error(), friendIDList, user.UserID)
} }
} if len(friendIDList) > 0 {
if err := db.DB.AddFriendToCache(user.UserID, friendIDList...); err != nil {
log.NewWarn("0", utils.GetSelfFuncName(), err.Error(), friendIDList, user.UserID)
}
}
}()
} }
wg.Wait()
log.NewInfo("0", utils.GetSelfFuncName(), "ok") log.NewInfo("0", utils.GetSelfFuncName(), "ok")
return nil return nil
} }
func updateAllBlackListToCache(userList []db.User) error { func updateAllBlackListToCache(userList []db.User) error {
log.NewInfo("0", utils.GetSelfFuncName()) log.NewInfo("0", utils.GetSelfFuncName())
wg := &sync.WaitGroup{}
wg.Add(len(userList))
for _, user := range userList { for _, user := range userList {
blackIDList, err := imdb.GetBlackIDListByUserID(user.UserID) go func() {
if err != nil { defer wg.Done()
log.NewWarn("", utils.GetSelfFuncName(), err.Error()) blackIDList, err := imdb.GetBlackIDListByUserID(user.UserID)
continue if err != nil {
} log.NewWarn("", utils.GetSelfFuncName(), err.Error())
if len(blackIDList) > 0 { return
if err := db.DB.AddBlackUserToCache(user.UserID, blackIDList...); err != nil {
log.NewWarn("0", utils.GetSelfFuncName(), err.Error())
} }
} if len(blackIDList) > 0 {
if err := db.DB.AddBlackUserToCache(user.UserID, blackIDList...); err != nil {
log.NewWarn("0", utils.GetSelfFuncName(), err.Error())
}
}
}()
} }
wg.Wait()
log.NewInfo("0", utils.GetSelfFuncName(), "ok") log.NewInfo("0", utils.GetSelfFuncName(), "ok")
return nil return nil
} }

Loading…
Cancel
Save