mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-11 12:36:00 +08:00
group cache
This commit is contained in:
Vendored
+11
-19
@@ -106,7 +106,7 @@ func (g *GroupCacheRedis) getGroupMemberNumKey(groupID string) string {
|
||||
|
||||
// / groupInfo
|
||||
func (g *GroupCacheRedis) GetGroupsInfo(ctx context.Context, groupIDs []string) (groups []*relationTb.GroupModel, err error) {
|
||||
return GetCacheFor(ctx, g.rcClient, groupIDs, func(ctx context.Context, groupID string) (*relationTb.GroupModel, error) {
|
||||
return GetCacheFor(ctx, groupIDs, func(ctx context.Context, groupID string) (*relationTb.GroupModel, error) {
|
||||
return g.GetGroupInfo(ctx, groupID)
|
||||
})
|
||||
}
|
||||
@@ -151,28 +151,20 @@ func (g *GroupCacheRedis) DelJoinedSuperGroupIDs(ctx context.Context, userID str
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) GetJoinedSuperGroupIDs(ctx context.Context, userID string) (joinedSuperGroupIDs []string, err error) {
|
||||
getJoinedSuperGroupIDList := func() (string, error) {
|
||||
userToSuperGroup, err := g.mongoDB.GetSuperGroupByUserID(ctx, userID)
|
||||
return GetCache(ctx, g.rcClient, g.getJoinedSuperGroupsIDKey(userID), g.expireTime, func(ctx context.Context) ([]string, error) {
|
||||
userGroup, err := g.mongoDB.GetSuperGroupByUserID(ctx, userID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
bytes, err := json.Marshal(userToSuperGroup.GroupIDList)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "joinedSuperGroupIDs", joinedSuperGroupIDs)
|
||||
}()
|
||||
joinedSuperGroupListStr, err := g.rcClient.Fetch(g.getJoinedSuperGroupsIDKey(userID), time.Second*30*60, getJoinedSuperGroupIDList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(joinedSuperGroupListStr), &joinedSuperGroupIDs)
|
||||
return joinedSuperGroupIDs, utils.Wrap(err, "")
|
||||
return userGroup.GroupIDs, nil
|
||||
})
|
||||
}
|
||||
|
||||
//// groupMembersHash
|
||||
//func (g *GroupCacheRedis) GetGroupsMembersHash(ctx context.Context, groupIDs []string) (map[string]uint64, error) {
|
||||
// return GetCache(ctx, g.rcClient, g.getGroupMembersHashKey(groupID), g.expireTime, "")
|
||||
//}
|
||||
|
||||
// groupMembersHash
|
||||
func (g *GroupCacheRedis) GetGroupMembersHash(ctx context.Context, groupID string) (hashCodeUint64 uint64, err error) {
|
||||
generateHash := func() (string, error) {
|
||||
|
||||
Vendored
+1
-1
@@ -36,7 +36,7 @@ func GetCache[T any](ctx context.Context, rcClient *rockscache.Client, key strin
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func GetCacheFor[E any, T any](ctx context.Context, rcClient *rockscache.Client, list []E, fn func(ctx context.Context, item E) (T, error)) ([]T, error) {
|
||||
func GetCacheFor[E any, T any](ctx context.Context, list []E, fn func(ctx context.Context, item E) (T, error)) ([]T, error) {
|
||||
rs := make([]T, 0, len(list))
|
||||
for _, e := range list {
|
||||
r, err := fn(ctx, e)
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
"github.com/go-redis/redis/v8"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"gorm.io/gorm"
|
||||
"math/big"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//type GroupInterface GroupDataBaseInterface
|
||||
@@ -25,6 +27,11 @@ type BatchUpdateGroupMember struct {
|
||||
Map map[string]any
|
||||
}
|
||||
|
||||
type GroupSimpleUserID struct {
|
||||
Hash uint64
|
||||
UserIDs []string
|
||||
}
|
||||
|
||||
type GroupInterface interface {
|
||||
CreateGroup(ctx context.Context, groups []*relationTb.GroupModel, groupMembers []*relationTb.GroupMemberModel) error
|
||||
TakeGroup(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error)
|
||||
@@ -41,7 +48,7 @@ type GroupInterface interface {
|
||||
SearchGroupMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (uint32, []*relationTb.GroupMemberModel, error)
|
||||
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relationTb.GroupMemberModel) error
|
||||
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string][]string, error)
|
||||
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*GroupSimpleUserID, error)
|
||||
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
||||
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error // 转让群
|
||||
UpdateGroupMember(ctx context.Context, groupID string, userID string, data map[string]any) error
|
||||
@@ -125,7 +132,7 @@ func (g *GroupController) DeleteGroupMember(ctx context.Context, groupID string,
|
||||
return g.database.DeleteGroupMember(ctx, groupID, userIDs)
|
||||
}
|
||||
|
||||
func (g *GroupController) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string][]string, error) {
|
||||
func (g *GroupController) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*GroupSimpleUserID, error) {
|
||||
return g.database.MapGroupMemberUserID(ctx, groupIDs)
|
||||
}
|
||||
|
||||
@@ -197,7 +204,7 @@ type GroupDataBaseInterface interface {
|
||||
SearchGroupMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (uint32, []*relationTb.GroupMemberModel, error)
|
||||
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relationTb.GroupMemberModel) error
|
||||
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string][]string, error)
|
||||
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*GroupSimpleUserID, error)
|
||||
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
||||
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error // 转让群
|
||||
UpdateGroupMember(ctx context.Context, groupID string, userID string, data map[string]any) error
|
||||
@@ -386,8 +393,24 @@ func (g *GroupDataBase) DeleteGroupMember(ctx context.Context, groupID string, u
|
||||
})
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string][]string, error) {
|
||||
return g.groupMemberDB.FindJoinUserID(ctx, groupIDs)
|
||||
func (g *GroupDataBase) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*GroupSimpleUserID, error) {
|
||||
mapGroupUserIDs, err := g.groupMemberDB.FindJoinUserID(ctx, groupIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := make(map[string]*GroupSimpleUserID)
|
||||
for _, groupID := range groupIDs {
|
||||
users := &GroupSimpleUserID{
|
||||
UserIDs: mapGroupUserIDs[groupID],
|
||||
}
|
||||
if len(users.UserIDs) > 0 {
|
||||
utils.Sort(users.UserIDs, true)
|
||||
bi := big.NewInt(0)
|
||||
bi.SetString(utils.Md5(strings.Join(users.UserIDs, ";"))[0:8], 16)
|
||||
}
|
||||
res[groupID] = users
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
|
||||
|
||||
Reference in New Issue
Block a user