This commit is contained in:
wangchuxiao 2023-02-07 18:43:43 +08:00
parent 795a90a194
commit f4baf847ca
6 changed files with 59 additions and 7 deletions

View File

@ -47,7 +47,7 @@ func (c *ConversationCache) getSuperGroupRecvNotNotifyUserIDsKey(groupID string)
return superGroupRecvMsgNotNotifyUserIDsKey + groupID return superGroupRecvMsgNotNotifyUserIDsKey + groupID
} }
func (c *ConversationCache) GetUserConversationIDs(ctx context.Context, ownerUserID string) (conversationIDs []string, err error) { func (c *ConversationCache) GetUserConversationIDs(ctx context.Context, ownerUserID string, f func(userID string) ([]string, error)) (conversationIDs []string, err error) {
//getConversationIDs := func() (string, error) { //getConversationIDs := func() (string, error) {
// conversationIDs, err := relation.GetConversationIDsByUserID(ownerUserID) // conversationIDs, err := relation.GetConversationIDsByUserID(ownerUserID)
// if err != nil { // if err != nil {
@ -69,11 +69,11 @@ func (c *ConversationCache) GetUserConversationIDs(ctx context.Context, ownerUse
//} //}
//return conversationIDs, nil //return conversationIDs, nil
return GetCache(c.rcClient, c.getConversationIDsKey(ownerUserID), time.Second*30*60, func() ([]string, error) { return GetCache(c.rcClient, c.getConversationIDsKey(ownerUserID), time.Second*30*60, func() ([]string, error) {
return relation.GetConversationIDsByUserID(ownerUserID) return f(ownerUserID)
}) })
} }
func (c *ConversationCache) GetUserConversationIDs1(ctx context.Context, ownerUserID string, fn func() (any, error)) (conversationIDs []string, err error) { func (c *ConversationCache) GetUserConversationIDs1(ctx context.Context, ownerUserID string) (conversationIDs []string, err error) {
//getConversationIDs := func() (string, error) { //getConversationIDs := func() (string, error) {
// conversationIDs, err := relation.GetConversationIDsByUserID(ownerUserID) // conversationIDs, err := relation.GetConversationIDsByUserID(ownerUserID)
// if err != nil { // if err != nil {

13
pkg/common/db/cache/extend_msg_set.go vendored Normal file
View File

@ -0,0 +1,13 @@
package cache
import (
"Open_IM/pkg/common/db/relation"
"github.com/dtm-labs/rockscache"
"time"
)
type ExtendMsgSetCache struct {
friendDB *relation.FriendGorm
expireTime time.Duration
rcClient *rockscache.Client
}

View File

@ -1,6 +1,7 @@
package localcache package localcache
import ( import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/proto/group" "Open_IM/pkg/proto/group"
"context" "context"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -27,12 +28,31 @@ func NewGroupMemberIDsLocalCache(rpc *grpc.ClientConn) GroupLocalCache {
} }
} }
func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string) []string { func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error) {
g.lock.Lock()
defer g.lock.Unlock()
resp, err := g.group.GetGroupAbstractInfo(ctx, &group.GetGroupAbstractInfoReq{ resp, err := g.group.GetGroupAbstractInfo(ctx, &group.GetGroupAbstractInfoReq{
GroupIDs: nil, GroupIDs: []string{groupID},
}) })
if err != nil { if err != nil {
return nil return nil, err
} }
return []string{} if len(resp.GroupAbstractInfos) < 0 {
return nil, constant.ErrGroupIDNotFound
}
localHashInfo, ok := g.cache[groupID]
if ok && localHashInfo.memberListHash == resp.GroupAbstractInfos[0].GroupMemberListHash {
return localHashInfo.userIDs, nil
}
groupMembersResp, err := g.group.GetGroupMemberList(ctx, &group.GetGroupMemberListReq{
GroupID: groupID,
})
if err != nil {
return nil, err
}
g.cache[groupID] = GroupMemberIDsHash{
memberListHash: resp.GroupAbstractInfos[0].GroupMemberListHash,
userIDs: groupMembersResp.Members,
}
return g.cache[groupID].userIDs, nil
} }

View File

@ -1,6 +1,8 @@
package unrelation package unrelation
import ( import (
commonPb "Open_IM/pkg/proto/sdk_ws"
"context"
"strconv" "strconv"
"strings" "strings"
) )
@ -51,3 +53,17 @@ func (e *ExtendMsgSet) SplitSourceIDAndGetIndex() int32 {
index, _ := strconv.Atoi(l[len(l)-1]) index, _ := strconv.Atoi(l[len(l)-1])
return int32(index) return int32(index)
} }
type GetAllExtendMsgSetOpts struct {
ExcludeExtendMsgs bool
}
type ExtendMsgSetInterface interface {
CreateExtendMsgSet(ctx context.Context, set *ExtendMsgSet) error
GetAllExtendMsgSet(ctx context.Context, ID string, opts *GetAllExtendMsgSetOpts) (sets []*ExtendMsgSet, err error)
GetExtendMsgSet(ctx context.Context, sourceID string, sessionType int32, maxMsgUpdateTime int64) (*ExtendMsgSet, error)
InsertExtendMsg(ctx context.Context, sourceID string, sessionType int32, msg *ExtendMsg) error
InsertOrUpdateReactionExtendMsgSet(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, msgFirstModifyTime int64, reactionExtensionList map[string]*commonPb.KeyValue) error
DeleteReactionExtendMsgSet(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, msgFirstModifyTime int64, reactionExtensionList map[string]*commonPb.KeyValue) error
GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, maxMsgUpdateTime int64) (extendMsg *ExtendMsg, err error)
}

View File

@ -1,5 +1,7 @@
package unrelation package unrelation
import "go.mongodb.org/mongo-driver/mongo"
const ( const (
CSuperGroup = "super_group" CSuperGroup = "super_group"
CUserToSuperGroup = "user_to_super_group" CUserToSuperGroup = "user_to_super_group"
@ -24,4 +26,5 @@ func (UserToSuperGroupModel) TableName() string {
} }
type SuperGroupModelInterface interface { type SuperGroupModelInterface interface {
CreateSuperGroup(sCtx mongo.SessionContext, groupID string, initMemberIDs []string) error
} }