Merge remote-tracking branch 'origin/localcache' into localcache

This commit is contained in:
Gordon 2024-01-16 11:21:29 +08:00
commit b2eae0999c
6 changed files with 34 additions and 24 deletions

View File

@ -144,6 +144,7 @@ func (m *msgServer) sendMsgNotification(
}
func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *pbmsg.SendMsgReq) (resp *pbmsg.SendMsgResp, err error) {
log.ZDebug(ctx, "sendMsgSingleChat return")
if err := m.messageVerification(ctx, req); err != nil {
return nil, err
}

View File

@ -16,6 +16,7 @@ package msg
import (
"context"
"github.com/OpenIMSDK/tools/log"
"math/rand"
"strconv"
"time"
@ -186,7 +187,8 @@ func (m *msgServer) modifyMessageByUserMessageReceiveOpt(
sessionType int,
pb *msg.SendMsgReq,
) (bool, error) {
opt, err := m.User.GetUserGlobalMsgRecvOpt(ctx, userID)
defer log.ZDebug(ctx, "modifyMessageByUserMessageReceiveOpt return")
opt, err := m.User.GetUserGlobalMsgRecvOpt(ctx, userID) // todo local cache
if err != nil {
return false, err
}
@ -202,7 +204,7 @@ func (m *msgServer) modifyMessageByUserMessageReceiveOpt(
return true, nil
}
// conversationID := utils.GetConversationIDBySessionType(conversationID, sessionType)
singleOpt, err := m.Conversation.GetSingleConversationRecvMsgOpt(ctx, userID, conversationID)
singleOpt, err := m.Conversation.GetSingleConversationRecvMsgOpt(ctx, userID, conversationID) // todo local cache
if errs.ErrRecordNotFound.Is(err) {
return true, nil
} else if err != nil {

20
pkg/rpccache/common.go Normal file
View File

@ -0,0 +1,20 @@
package rpccache
func newListMap[V comparable](values []V, err error) (*listMap[V], error) {
if err != nil {
return nil, err
}
lm := &listMap[V]{
List: values,
Map: make(map[V]struct{}, len(values)),
}
for _, value := range values {
lm.Map[value] = struct{}{}
}
return lm, nil
}
type listMap[V comparable] struct {
List []V
Map map[V]struct{}
}

View File

@ -19,7 +19,9 @@ func NewConversationLocalCache(client rpcclient.ConversationRpcClient, cli redis
localcache.WithLocalSlotSize(lc.SlotSize),
),
}
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
if lc.Enable() {
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
}
return x
}

View File

@ -19,7 +19,9 @@ func NewFriendLocalCache(client rpcclient.FriendRpcClient, cli redis.UniversalCl
localcache.WithLocalSlotSize(lc.SlotSize),
),
}
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
if lc.Enable() {
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
}
return x
}

View File

@ -19,7 +19,9 @@ func NewGroupLocalCache(client rpcclient.GroupRpcClient, cli redis.UniversalClie
localcache.WithLocalSlotSize(lc.SlotSize),
),
}
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
if lc.Enable() {
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
}
return x
}
@ -28,25 +30,6 @@ type GroupLocalCache struct {
local localcache.Cache[any]
}
type listMap[V comparable] struct {
List []V
Map map[V]struct{}
}
func newListMap[V comparable](values []V, err error) (*listMap[V], error) {
if err != nil {
return nil, err
}
lm := &listMap[V]{
List: values,
Map: make(map[V]struct{}, len(values)),
}
for _, value := range values {
lm.Map[value] = struct{}{}
}
return lm, nil
}
func (g *GroupLocalCache) getGroupMemberIDs(ctx context.Context, groupID string) (val *listMap[string], err error) {
log.ZDebug(ctx, "GroupLocalCache getGroupMemberIDs req", "groupID", groupID)
defer func() {