From 708f55004c0b0941ecde44e75ecb98def4b09ac2 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 22 May 2023 19:00:46 +0800 Subject: [PATCH] conversation --- pkg/a2r/api2rpc.go | 1 - pkg/common/db/cache/conversation.go | 24 ++++++++++-------------- pkg/common/db/controller/conversation.go | 5 +++++ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/a2r/api2rpc.go b/pkg/a2r/api2rpc.go index d6b56696d..7c21961e9 100644 --- a/pkg/a2r/api2rpc.go +++ b/pkg/a2r/api2rpc.go @@ -36,7 +36,6 @@ func Call[A, B, C any]( } data, err := rpc(cli, c, &req) if err != nil { - log.ZError(c, "rpc call error", err, "req", req) apiresp.GinError(c, err) // RPC调用失败 return } diff --git a/pkg/common/db/cache/conversation.go b/pkg/common/db/cache/conversation.go index f50f6decb..da5af8094 100644 --- a/pkg/common/db/cache/conversation.go +++ b/pkg/common/db/cache/conversation.go @@ -104,18 +104,6 @@ func (c *ConversationRedisCache) getConversationHasReadSeqKey(ownerUserID, conve return conversationHasReadSeqKey + ownerUserID + ":" + conversationID } -func (c *ConversationRedisCache) getAllConversationIDsKeys(ctx context.Context, ownerUserID string) ([]string, []string, error) { - conversationIDs, err := c.GetUserConversationIDs(ctx, ownerUserID) - if err != nil { - return nil, nil, err - } - var keys []string - for _, conversarionID := range conversationIDs { - keys = append(keys, c.getConversationKey(ownerUserID, conversarionID)) - } - return keys, conversationIDs, nil -} - func (c *ConversationRedisCache) GetUserConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) { return getCache(ctx, c.rcClient, c.getConversationIDsKey(ownerUserID), c.expireTime, func(ctx context.Context) ([]string, error) { return c.conversationDB.FindUserIDAllConversationID(ctx, ownerUserID) @@ -196,10 +184,14 @@ func (c *ConversationRedisCache) GetConversations(ctx context.Context, ownerUser } func (c *ConversationRedisCache) GetUserAllConversations(ctx context.Context, ownerUserID string) ([]*relationTb.ConversationModel, error) { - keys, _, err := c.getAllConversationIDsKeys(ctx, ownerUserID) + conversationIDs, err := c.GetUserConversationIDs(ctx, ownerUserID) if err != nil { return nil, err } + var keys []string + for _, conversarionID := range conversationIDs { + keys = append(keys, c.getConversationKey(ownerUserID, conversarionID)) + } return batchGetCache(ctx, c.rcClient, keys, c.expireTime, c.getConversationIndex, func(ctx context.Context) ([]*relationTb.ConversationModel, error) { return c.conversationDB.FindUserIDAllConversations(ctx, ownerUserID) }) @@ -268,10 +260,14 @@ func (c *ConversationRedisCache) getUserAllHasReadSeqsIndex(conversationID strin } func (c *ConversationRedisCache) GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (map[string]int64, error) { - keys, conversationIDs, err := c.getAllConversationIDsKeys(ctx, ownerUserID) + conversationIDs, err := c.GetUserConversationIDs(ctx, ownerUserID) if err != nil { return nil, err } + var keys []string + for _, conversarionID := range conversationIDs { + keys = append(keys, c.getConversationHasReadSeqKey(ownerUserID, conversarionID)) + } return batchGetCacheMap(ctx, c.rcClient, keys, conversationIDs, c.expireTime, c.getUserAllHasReadSeqsIndex, func(ctx context.Context) (map[string]int64, error) { return c.conversationDB.GetUserAllHasReadSeqs(ctx, ownerUserID) }) diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index 95dfd9a4c..22e4b8dff 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -63,6 +63,11 @@ func (c *ConversationDataBase) SetUsersConversationFiledTx(ctx context.Context, return err } cache = cache.DelUsersConversation(conversation.ConversationID, haveUserIDs...) + if _, ok := filedMap["has_read_seq"]; ok { + for _, userID := range haveUserIDs { + cache = cache.DelUserAllHasReadSeqs(userID, conversation.ConversationID) + } + } } NotUserIDs := utils.DifferenceString(haveUserIDs, userIDs) log.ZDebug(ctx, "SetUsersConversationFiledTx", "NotUserIDs", NotUserIDs, "haveUserIDs", haveUserIDs, "userIDs", userIDs)