mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-21 12:39:57 +08:00
local cache
This commit is contained in:
parent
ee9c9eb97c
commit
a84ad774f7
@ -58,7 +58,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
|
|||||||
data.MsgData.ContentType >= constant.NotificationBegin {
|
data.MsgData.ContentType >= constant.NotificationBegin {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
black, err := m.friend.IsBlocked(ctx, data.MsgData.SendID, data.MsgData.RecvID)
|
black, err := m.friend.IsBlack(ctx, data.MsgData.SendID, data.MsgData.RecvID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -23,26 +23,47 @@ type FriendLocalCache struct {
|
|||||||
client rpcclient.FriendRpcClient
|
client rpcclient.FriendRpcClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendLocalCache) GetFriendIDs(ctx context.Context, ownerUserID string) ([]string, error) {
|
func (f *FriendLocalCache) GetFriendIDs(ctx context.Context, ownerUserID string) (val []string, err error) {
|
||||||
log.ZDebug(ctx, "FriendLocalCache GetFriendIDs req", "ownerUserID", ownerUserID)
|
log.ZDebug(ctx, "FriendLocalCache GetFriendIDs req", "ownerUserID", ownerUserID)
|
||||||
|
defer func() {
|
||||||
|
if err == nil {
|
||||||
|
log.ZDebug(ctx, "FriendLocalCache GetFriendIDs return", "value", val)
|
||||||
|
} else {
|
||||||
|
log.ZError(ctx, "FriendLocalCache GetFriendIDs return", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
return localcache.AnyValue[[]string](f.local.Get(ctx, cachekey.GetFriendIDsKey(ownerUserID), func(ctx context.Context) (any, error) {
|
return localcache.AnyValue[[]string](f.local.Get(ctx, cachekey.GetFriendIDsKey(ownerUserID), func(ctx context.Context) (any, error) {
|
||||||
log.ZDebug(ctx, "FriendLocalCache GetFriendIDs call rpc", "ownerUserID", ownerUserID)
|
log.ZDebug(ctx, "FriendLocalCache GetFriendIDs call rpc", "ownerUserID", ownerUserID)
|
||||||
return f.client.GetFriendIDs(ctx, ownerUserID)
|
return f.client.GetFriendIDs(ctx, ownerUserID)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendLocalCache) IsFriend(ctx context.Context, possibleFriendUserID, userID string) (bool, error) {
|
func (f *FriendLocalCache) IsFriend(ctx context.Context, possibleFriendUserID, userID string) (val bool, err error) {
|
||||||
log.ZDebug(ctx, "FriendLocalCache IsFriend req", "possibleFriendUserID", possibleFriendUserID, "userID", userID)
|
log.ZDebug(ctx, "FriendLocalCache IsFriend req", "possibleFriendUserID", possibleFriendUserID, "userID", userID)
|
||||||
|
defer func() {
|
||||||
|
if err == nil {
|
||||||
|
log.ZDebug(ctx, "FriendLocalCache IsFriend return", "value", val)
|
||||||
|
} else {
|
||||||
|
log.ZError(ctx, "FriendLocalCache IsFriend return", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
return localcache.AnyValue[bool](f.local.Get(ctx, cachekey.GetIsFriendKey(possibleFriendUserID, userID), func(ctx context.Context) (any, error) {
|
return localcache.AnyValue[bool](f.local.Get(ctx, cachekey.GetIsFriendKey(possibleFriendUserID, userID), func(ctx context.Context) (any, error) {
|
||||||
log.ZDebug(ctx, "FriendLocalCache IsFriend rpc", "possibleFriendUserID", possibleFriendUserID, "userID", userID)
|
log.ZDebug(ctx, "FriendLocalCache IsFriend rpc", "possibleFriendUserID", possibleFriendUserID, "userID", userID)
|
||||||
return f.client.IsFriend(ctx, possibleFriendUserID, userID)
|
return f.client.IsFriend(ctx, possibleFriendUserID, userID)
|
||||||
}, option.NewOption().WithLink(cachekey.GetFriendIDsKey(possibleFriendUserID), cachekey.GetFriendIDsKey(userID))))
|
}, option.NewOption().WithLink(cachekey.GetFriendIDsKey(possibleFriendUserID), cachekey.GetFriendIDsKey(userID))))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendLocalCache) IsBlocked(ctx context.Context, possibleBlackUserID, userID string) (bool, error) {
|
func (f *FriendLocalCache) IsBlack(ctx context.Context, possibleBlackUserID, userID string) (val bool, err error) {
|
||||||
log.ZDebug(ctx, "FriendLocalCache IsBlocked req", "possibleBlackUserID", possibleBlackUserID, "userID", userID)
|
log.ZDebug(ctx, "FriendLocalCache IsBlack req", "possibleBlackUserID", possibleBlackUserID, "userID", userID)
|
||||||
|
defer func() {
|
||||||
|
if err == nil {
|
||||||
|
log.ZDebug(ctx, "FriendLocalCache IsBlack return", "value", val)
|
||||||
|
} else {
|
||||||
|
log.ZError(ctx, "FriendLocalCache IsBlack return", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
return localcache.AnyValue[bool](f.local.Get(ctx, cachekey.GetIsBlackIDsKey(possibleBlackUserID, userID), func(ctx context.Context) (any, error) {
|
return localcache.AnyValue[bool](f.local.Get(ctx, cachekey.GetIsBlackIDsKey(possibleBlackUserID, userID), func(ctx context.Context) (any, error) {
|
||||||
log.ZDebug(ctx, "FriendLocalCache IsBlocked rpc", "possibleBlackUserID", possibleBlackUserID, "userID", userID)
|
log.ZDebug(ctx, "FriendLocalCache IsBlack rpc", "possibleBlackUserID", possibleBlackUserID, "userID", userID)
|
||||||
return f.client.IsBlocked(ctx, possibleBlackUserID, userID)
|
return f.client.IsBlack(ctx, possibleBlackUserID, userID)
|
||||||
}, option.NewOption().WithLink(cachekey.GetBlackIDsKey(possibleBlackUserID), cachekey.GetBlackIDsKey(userID))))
|
}, option.NewOption().WithLink(cachekey.GetBlackIDsKey(possibleBlackUserID), cachekey.GetBlackIDsKey(userID))))
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func (f *FriendRpcClient) GetFriendIDs(ctx context.Context, ownerUserID string)
|
|||||||
return resp.FriendIDs, nil
|
return resp.FriendIDs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *FriendRpcClient) IsBlocked(ctx context.Context, possibleBlackUserID, userID string) (bool, error) {
|
func (b *FriendRpcClient) IsBlack(ctx context.Context, possibleBlackUserID, userID string) (bool, error) {
|
||||||
r, err := b.Client.IsBlack(ctx, &friend.IsBlackReq{UserID1: possibleBlackUserID, UserID2: userID})
|
r, err := b.Client.IsBlack(ctx, &friend.IsBlackReq{UserID1: possibleBlackUserID, UserID2: userID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user