From 923e94359134f429baf093a2c572c0b77cd8e6b8 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 14 Jun 2023 18:17:32 +0800 Subject: [PATCH 1/6] err --- internal/rpc/msg/as_read.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/msg/as_read.go b/internal/rpc/msg/as_read.go index 19c97fb19..a79c57e86 100644 --- a/internal/rpc/msg/as_read.go +++ b/internal/rpc/msg/as_read.go @@ -93,7 +93,7 @@ func (m *msgServer) MarkConversationAsRead(ctx context.Context, req *msg.MarkCon return } hasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID) - if err != nil && errors.Unwrap(err) != redis.Nil { + if err != nil && errs.Unwrap(err) != redis.Nil { return } log.ZDebug(ctx, "MarkConversationAsRead", "hasReadSeq", hasReadSeq, "req.HasReadSeq", req.HasReadSeq) From fef55433927e287b01c47d36075ece59026b1182 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 15 Jun 2023 10:22:28 +0800 Subject: [PATCH 2/6] get con from cache --- pkg/common/db/controller/conversation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index d34c1c890..4cdf2c22e 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -265,5 +265,5 @@ func (c *conversationDatabase) GetUserAllHasReadSeqs(ctx context.Context, ownerU } func (c *conversationDatabase) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationTb.ConversationModel, error) { - return c.conversationDB.GetConversationsByConversationID(ctx, conversationIDs) + return c.cache.GetConversationsByConversationID(ctx, conversationIDs) } From 61953f4f7d213e75e255d4fae59f1d3546a38706 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 15 Jun 2023 10:22:37 +0800 Subject: [PATCH 3/6] get con from cache --- internal/rpc/msg/as_read.go | 8 ++++---- pkg/common/db/cache/conversation.go | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/rpc/msg/as_read.go b/internal/rpc/msg/as_read.go index 0b3838307..07a2e6592 100644 --- a/internal/rpc/msg/as_read.go +++ b/internal/rpc/msg/as_read.go @@ -64,7 +64,7 @@ func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadR if hasReadSeq > maxSeq { return nil, errs.ErrArgs.Wrap("hasReadSeq must not be bigger than maxSeq") } - conversations, err := m.Conversation.GetConversationsByConversationID(ctx, []string{req.ConversationID}) + conversation, err := m.Conversation.GetConversation(ctx, req.UserID, req.ConversationID) if err != nil { return } @@ -81,14 +81,14 @@ func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadR return } } - if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversations[0].ConversationType, req.UserID, m.conversationAndGetRecvID(conversations[0], req.UserID), req.Seqs, hasReadSeq); err != nil { + if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID, m.conversationAndGetRecvID(conversation, req.UserID), req.Seqs, hasReadSeq); err != nil { return } return &msg.MarkMsgsAsReadResp{}, nil } func (m *msgServer) MarkConversationAsRead(ctx context.Context, req *msg.MarkConversationAsReadReq) (resp *msg.MarkConversationAsReadResp, err error) { - conversations, err := m.Conversation.GetConversationsByConversationID(ctx, []string{req.ConversationID}) + conversation, err := m.Conversation.GetConversation(ctx, req.UserID, req.ConversationID) if err != nil { return } @@ -114,7 +114,7 @@ func (m *msgServer) MarkConversationAsRead(ctx context.Context, req *msg.MarkCon } hasReadSeq = req.HasReadSeq } - if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversations[0].ConversationType, req.UserID, m.conversationAndGetRecvID(conversations[0], req.UserID), seqs, hasReadSeq); err != nil { + if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID, m.conversationAndGetRecvID(conversation, req.UserID), seqs, hasReadSeq); err != nil { return } return &msg.MarkConversationAsReadResp{}, nil diff --git a/pkg/common/db/cache/conversation.go b/pkg/common/db/cache/conversation.go index da5af8094..64ae93598 100644 --- a/pkg/common/db/cache/conversation.go +++ b/pkg/common/db/cache/conversation.go @@ -57,6 +57,9 @@ type ConversationCache interface { GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (map[string]int64, error) DelUserAllHasReadSeqs(ownerUserID string, conversationIDs ...string) ConversationCache + + GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationTb.ConversationModel, error) + DelConversationByConversationID(conversationIDs ...string) ConversationCache } func NewConversationRedis(rdb redis.UniversalClient, opts rockscache.Options, db relationTb.ConversationModelInterface) ConversationCache { @@ -280,3 +283,11 @@ func (c *ConversationRedisCache) DelUserAllHasReadSeqs(ownerUserID string, conve } return cache } + +func (c *ConversationRedisCache) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationTb.ConversationModel, error) { + panic("implement me") +} + +func (c *ConversationRedisCache) DelConversationByConversationID(conversationIDs ...string) ConversationCache { + panic("implement me") +} From a8fa9431421e2f90537308a54b49c7046aec2eab Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Thu, 15 Jun 2023 10:52:41 +0800 Subject: [PATCH 4/6] PageGetGroupMember --- internal/rpc/group/fill.go | 32 ++++++++++++++++++++++++++++++++ internal/rpc/group/group.go | 16 ++-------------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/internal/rpc/group/fill.go b/internal/rpc/group/fill.go index 0e3abff43..4302e3bf0 100644 --- a/internal/rpc/group/fill.go +++ b/internal/rpc/group/fill.go @@ -77,3 +77,35 @@ func (s *groupServer) TakeGroupOwner(ctx context.Context, groupID string) (*rela } return owner, nil } + +func (s *groupServer) PageGetGroupMember(ctx context.Context, groupID string, pageNumber, showNumber int32) (uint32, []*relationTb.GroupMemberModel, error) { + total, members, err := s.GroupDatabase.PageGetGroupMember(ctx, groupID, pageNumber, showNumber) + if err != nil { + return 0, nil, err + } + emptyUserIDs := make(map[string]struct{}) + for _, member := range members { + if member.Nickname == "" || member.FaceURL == "" { + emptyUserIDs[member.UserID] = struct{}{} + } + } + if len(emptyUserIDs) > 0 { + users, err := s.User.GetPublicUserInfoMap(ctx, utils.Keys(emptyUserIDs), true) + if err != nil { + return 0, nil, err + } + for i, member := range members { + user, ok := users[member.UserID] + if !ok { + continue + } + if member.Nickname == "" { + members[i].Nickname = user.Nickname + } + if member.FaceURL == "" { + members[i].FaceURL = user.FaceURL + } + } + } + return total, members, nil +} diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 2fb35c0b3..d1a4dc1e4 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -410,25 +410,13 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGroupMemberListReq) (*pbGroup.GetGroupMemberListResp, error) { resp := &pbGroup.GetGroupMemberListResp{} - total, members, err := s.GroupDatabase.PageGetGroupMember(ctx, req.GroupID, req.Pagination.PageNumber, req.Pagination.ShowNumber) + total, members, err := s.PageGetGroupMember(ctx, req.GroupID, req.Pagination.PageNumber, req.Pagination.ShowNumber) log.ZDebug(ctx, "GetGroupMemberList", "total", total, "members", members, "length", len(members)) if err != nil { return nil, err } resp.Total = total - nameMap, err := s.GetUsernameMap(ctx, utils.Filter(members, func(e *relationTb.GroupMemberModel) (string, bool) { - return e.UserID, e.Nickname == "" - }), true) - if err != nil { - return nil, err - } - log.ZDebug(ctx, "GetGroupMemberList", "nameMap", nameMap) - resp.Members = utils.Slice(members, func(e *relationTb.GroupMemberModel) *sdkws.GroupMemberFullInfo { - if e.Nickname == "" { - e.Nickname = nameMap[e.UserID] - } - return convert.Db2PbGroupMember(e) - }) + resp.Members = utils.Batch(convert.Db2PbGroupMember, members) log.ZDebug(ctx, "GetGroupMemberList", "resp", resp, "length", len(resp.Members)) return resp, nil } From 180c888ba73c4679c6eb1c30e04c32aa6d30ad49 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 15 Jun 2023 11:46:43 +0800 Subject: [PATCH 5/6] cache --- pkg/common/db/controller/conversation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index 4cdf2c22e..d34c1c890 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -265,5 +265,5 @@ func (c *conversationDatabase) GetUserAllHasReadSeqs(ctx context.Context, ownerU } func (c *conversationDatabase) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationTb.ConversationModel, error) { - return c.cache.GetConversationsByConversationID(ctx, conversationIDs) + return c.conversationDB.GetConversationsByConversationID(ctx, conversationIDs) } From e8427ee33e786beaa017a4d02109fd28d470fb41 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 15 Jun 2023 14:20:05 +0800 Subject: [PATCH 6/6] group --- internal/rpc/msg/verify.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/rpc/msg/verify.go b/internal/rpc/msg/verify.go index 6e0b2153c..f6903f9f9 100644 --- a/internal/rpc/msg/verify.go +++ b/internal/rpc/msg/verify.go @@ -89,6 +89,9 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe groupMemberInfo, err := m.Group.GetGroupMemberCache(ctx, data.MsgData.GroupID, data.MsgData.SendID) if err != nil { + if err == errs.ErrRecordNotFound { + return errs.ErrNotInGroupYet.Wrap(err.Error()) + } return err } if groupMemberInfo.RoleLevel == constant.GroupOwner {