diff --git a/pkg/common/db/localcache/conversation.go b/pkg/common/db/localcache/conversation.go index d991fa5a0..5d2e11f30 100644 --- a/pkg/common/db/localcache/conversation.go +++ b/pkg/common/db/localcache/conversation.go @@ -11,6 +11,7 @@ import ( type ConversationLocalCacheInterface interface { GetRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error) + GetConversationIDs(ctx context.Context, userID string) ([]string, error) } type ConversationLocalCache struct { @@ -40,3 +41,18 @@ func (g *ConversationLocalCache) GetRecvMsgNotNotifyUserIDs(ctx context.Context, } return resp.UserIDs, nil } + +func (g *ConversationLocalCache) GetConversationIDs(ctx context.Context, userID string) ([]string, error) { + conn, err := g.client.GetConn(ctx, config.Config.RpcRegisterName.OpenImConversationName) + if err != nil { + return nil, err + } + client := conversation.NewConversationClient(conn) + resp, err := client.GetConversationIDs(ctx, &conversation.GetConversationIDsReq{ + UserID: userID, + }) + if err != nil { + return nil, err + } + return resp.ConversationIDs, nil +} diff --git a/pkg/common/db/localcache/group.go b/pkg/common/db/localcache/group.go index 38cead1a6..5b3bdbd2d 100644 --- a/pkg/common/db/localcache/group.go +++ b/pkg/common/db/localcache/group.go @@ -46,7 +46,7 @@ func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string) if err != nil { return nil, err } - if len(resp.GroupAbstractInfos) < 0 { + if len(resp.GroupAbstractInfos) < 1 { return nil, errs.ErrGroupIDNotFound } localHashInfo, ok := g.cache[groupID] diff --git a/pkg/common/db/unrelation/mongo.go b/pkg/common/db/unrelation/mongo.go index a61af1a81..4491d9d9b 100644 --- a/pkg/common/db/unrelation/mongo.go +++ b/pkg/common/db/unrelation/mongo.go @@ -3,6 +3,9 @@ package unrelation import ( "context" "fmt" + "strings" + "time" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw/specialerror" @@ -11,8 +14,6 @@ import ( "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/x/bsonx" - "strings" - "time" ) type Mongo struct { diff --git a/pkg/common/db/unrelation/msg.go b/pkg/common/db/unrelation/msg.go index 344fd26a8..63eff5b0d 100644 --- a/pkg/common/db/unrelation/msg.go +++ b/pkg/common/db/unrelation/msg.go @@ -144,7 +144,6 @@ func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID strin bson.M{ "$project": bson.M{ "msgs": bson.M{ - // "$slice": []interface{}{"$msgs", beginIndex, num}, "$slice": bson.A{"$msgs", beginIndex, num}, }, }, @@ -154,16 +153,23 @@ func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID strin if err != nil { return nil, nil, errs.Wrap(err) } - log.ZDebug(ctx, "info", "beginIndex", beginIndex, "num", num) - var msgInfos []*table.MsgInfoModel - if err := cursor.All(ctx, &msgInfos); err != nil { - return nil, nil, err + defer cursor.Close(ctx) + var doc table.MsgDocModel + i := 0 + for cursor.Next(ctx) { + err := cursor.Decode(&doc) + if err != nil { + return nil, nil, err + } + if i == 0 { + break + } } - if len(msgInfos) < 1 { + if len(doc.Msg) < 1 { return nil, nil, errs.ErrRecordNotFound.Wrap("mongo GetMsgBySeqIndex failed, len is 0") } - log.ZDebug(ctx, "msgInfos", "num", len(msgInfos)) - for _, v := range msgInfos { + log.ZDebug(ctx, "msgInfos", "num", len(doc.Msg)) + for _, v := range doc.Msg { var msg sdkws.MsgData if err := proto.Unmarshal(v.Msg, &msg); err != nil { return nil, nil, err