|
|
|
@ -11,11 +11,11 @@ import (
|
|
|
|
|
commonPb "Open_IM/pkg/proto/sdk_ws"
|
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
|
"context"
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
"net"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
"sync"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type cacheServer struct {
|
|
|
|
@ -103,7 +103,11 @@ func SyncDB2Cache() error {
|
|
|
|
|
func DelRelationCache() {}
|
|
|
|
|
|
|
|
|
|
func updateAllUserToCache(userList []db.User) error {
|
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
|
wg.Add(len(userList))
|
|
|
|
|
for _, userInfo := range userList {
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
userInfoPb := &commonPb.UserInfo{
|
|
|
|
|
UserID: userInfo.UserID,
|
|
|
|
|
Nickname: userInfo.Nickname,
|
|
|
|
@ -123,7 +127,9 @@ func updateAllUserToCache(userList []db.User) 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")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -135,11 +141,15 @@ func updateAllGroupMemberListToCache() error {
|
|
|
|
|
log.NewWarn("0", utils.GetSelfFuncName(), "getAllGroupIDList failed", err.Error())
|
|
|
|
|
panic(err.Error())
|
|
|
|
|
}
|
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
|
wg.Add(len(groupIDList))
|
|
|
|
|
for _, groupID := range groupIDList {
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.NewWarn("", utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID", err.Error())
|
|
|
|
|
continue
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//log.NewDebug("", utils.GetSelfFuncName(), "groupMemberIDList", groupMemberIDList)
|
|
|
|
|
if len(groupMemberIDList) > 0 {
|
|
|
|
@ -147,43 +157,57 @@ func updateAllGroupMemberListToCache() error {
|
|
|
|
|
log.NewWarn("", utils.GetSelfFuncName(), "AddGroupMemberToCache", err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
wg.Wait()
|
|
|
|
|
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func updateAllFriendToCache(userList []db.User) error {
|
|
|
|
|
log.NewInfo("0", utils.GetSelfFuncName())
|
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
|
wg.Add(len(userList))
|
|
|
|
|
for _, user := range userList {
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
friendIDList, err := imdb.GetFriendIDListByUserID(user.UserID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.NewWarn("0", utils.GetSelfFuncName(), err.Error())
|
|
|
|
|
continue
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func updateAllBlackListToCache(userList []db.User) error {
|
|
|
|
|
log.NewInfo("0", utils.GetSelfFuncName())
|
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
|
wg.Add(len(userList))
|
|
|
|
|
for _, user := range userList {
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
blackIDList, err := imdb.GetBlackIDListByUserID(user.UserID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.NewWarn("", utils.GetSelfFuncName(), err.Error())
|
|
|
|
|
continue
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|