From 4bd4e0863ccb93d579707912aa210d41e504775e Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 22 Aug 2022 20:00:05 +0800 Subject: [PATCH 1/2] conversation update --- internal/rpc/conversation/conversaion.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index 023169a6b..6fb04dfd4 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -84,6 +84,10 @@ func (rpc *rpcConversation) ModifyConversationField(c context.Context, req *pbCo for _, v := range utils.DifferenceString(haveUserID, req.UserIDList) { conversation.OwnerUserID = v conversation.UpdateUnreadCountTime = utils.GetCurrentTimestampByMill() + err = rocksCache.DelUserConversationIDListFromCache(v) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), v, req.Conversation.ConversationID, err.Error()) + } err := imdb.SetOneConversation(conversation) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error()) From ec0cd9a3488fd2cd42fd7fda33454c7bfc716ebd Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Tue, 23 Aug 2022 12:06:44 +0800 Subject: [PATCH 2/2] conversation update --- internal/rpc/user/user.go | 9 +++++++-- .../db/mysql_model/im_mysql_model/conversation_model.go | 8 +++++--- pkg/common/db/rocks_cache/rocks_cache.go | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 9bf06b8fc..a7d7934ca 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -316,13 +316,18 @@ func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOp conversation.ConversationType = constant.GroupChatType } } - err := imdb.SetRecvMsgOpt(conversation) + isUpdate, err := imdb.SetRecvMsgOpt(conversation) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error()) resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} return resp, nil } - if err = rocksCache.DelConversationFromCache(conversation.OwnerUserID, conversation.ConversationID); err != nil { + if isUpdate { + err = rocksCache.DelConversationFromCache(conversation.OwnerUserID, conversation.ConversationID) + } else { + err = rocksCache.DelUserConversationIDListFromCache(conversation.OwnerUserID) + } + if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), conversation.ConversationID, err.Error()) } chat.ConversationChangeNotification(req.OperationID, req.OwnerUserID) diff --git a/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go b/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go index 2a645d54f..52fe1dcb9 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go @@ -41,16 +41,18 @@ func PeerUserSetConversation(conversation db.Conversation) error { } -func SetRecvMsgOpt(conversation db.Conversation) error { +func SetRecvMsgOpt(conversation db.Conversation) (bool, error) { + var isUpdate bool newConversation := conversation if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create") - return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error + return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error // if exist, then update record } else { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") //force update - return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID). + isUpdate = true + return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID). Updates(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt}).Error } } diff --git a/pkg/common/db/rocks_cache/rocks_cache.go b/pkg/common/db/rocks_cache/rocks_cache.go index 0cb41a8b5..a510b67a0 100644 --- a/pkg/common/db/rocks_cache/rocks_cache.go +++ b/pkg/common/db/rocks_cache/rocks_cache.go @@ -454,7 +454,7 @@ func GetUserConversationIDListFromCache(userID string) ([]string, error) { } func DelUserConversationIDListFromCache(userID string) error { - return db.DB.Rc.TagAsDeleted(conversationIDListCache + userID) + return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationIDListCache+userID), "DelUserConversationIDListFromCache err") } func GetConversationFromCache(ownerUserID, conversationID string) (*db.Conversation, error) { @@ -511,5 +511,5 @@ func GetUserAllConversationList(ownerUserID string) ([]db.Conversation, error) { } func DelConversationFromCache(ownerUserID, conversationID string) error { - return db.DB.Rc.TagAsDeleted(conversationCache + ownerUserID + ":" + conversationID) + return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationCache+ownerUserID+":"+conversationID), "DelConversationFromCache err") }