mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-20 03:39:50 +08:00
Merge remote-tracking branch 'origin/localcache' into localcache
This commit is contained in:
commit
b2eae0999c
@ -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
|
||||
}
|
||||
|
@ -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
20
pkg/rpccache/common.go
Normal 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{}
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user