mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-29 17:59:23 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
# Conflicts: # internal/rpc/group/group.go
This commit is contained in:
commit
9341a5f57f
122
internal/rpc/cache/cache.go
vendored
122
internal/rpc/cache/cache.go
vendored
@ -6,10 +6,12 @@ import (
|
|||||||
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
promePkg "Open_IM/pkg/common/prometheus"
|
promePkg "Open_IM/pkg/common/prometheus"
|
||||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
"Open_IM/pkg/common/trace_log"
|
||||||
pbCache "Open_IM/pkg/proto/cache"
|
pbCache "Open_IM/pkg/proto/cache"
|
||||||
|
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/OpenIMSDK/getcdv3"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -75,7 +77,7 @@ func (s *cacheServer) Run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.NewInfo("", "rpcRegisterIP", rpcRegisterIP)
|
log.NewInfo("", "rpcRegisterIP", rpcRegisterIP)
|
||||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10)
|
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
||||||
panic(utils.Wrap(err, "register cache module rpc to etcd err"))
|
panic(utils.Wrap(err, "register cache module rpc to etcd err"))
|
||||||
@ -89,91 +91,97 @@ func (s *cacheServer) Run() {
|
|||||||
log.NewInfo("0", "message cms rpc success")
|
log.NewInfo("0", "message cms rpc success")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *cacheServer) GetFriendIDListFromCache(_ context.Context, req *pbCache.GetFriendIDListFromCacheReq) (resp *pbCache.GetFriendIDListFromCacheResp, err error) {
|
func (s *cacheServer) GetFriendIDListFromCache(ctx context.Context, req *pbCache.GetFriendIDListFromCacheReq) (resp *pbCache.GetFriendIDListFromCacheResp, err error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
resp = &pbCache.GetFriendIDListFromCacheResp{CommonResp: &sdkws.CommonResp{}}
|
||||||
resp = &pbCache.GetFriendIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||||
friendIDList, err := rocksCache.GetFriendIDListFromCache(req.UserID)
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), nil, "req", req.String(), "resp", resp.String())
|
||||||
|
trace_log.ShowLog(ctx)
|
||||||
|
}()
|
||||||
|
friendIDList, err := rocksCache.GetFriendIDListFromCache(ctx, req.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache", err.Error())
|
constant.SetErrorForResp(err, resp.CommonResp)
|
||||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
return
|
||||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
|
||||||
return resp, nil
|
|
||||||
}
|
}
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), friendIDList)
|
|
||||||
resp.UserIDList = friendIDList
|
resp.UserIDList = friendIDList
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
return
|
||||||
return resp, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is for dtm call
|
// this is for dtm call
|
||||||
func (s *cacheServer) DelFriendIDListFromCache(_ context.Context, req *pbCache.DelFriendIDListFromCacheReq) (resp *pbCache.DelFriendIDListFromCacheResp, err error) {
|
func (s *cacheServer) DelFriendIDListFromCache(ctx context.Context, req *pbCache.DelFriendIDListFromCacheReq) (resp *pbCache.DelFriendIDListFromCacheResp, err error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
resp = &pbCache.DelFriendIDListFromCacheResp{CommonResp: &sdkws.CommonResp{}}
|
||||||
resp = &pbCache.DelFriendIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||||
if err := rocksCache.DelFriendIDListFromCache(req.UserID); err != nil {
|
defer func() {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.UserID, err.Error())
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), nil, "req", req.String(), "resp", resp.String())
|
||||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
trace_log.ShowLog(ctx)
|
||||||
resp.CommonResp.ErrMsg = err.Error()
|
}()
|
||||||
return resp, nil
|
if err := rocksCache.DelFriendIDListFromCache(ctx, req.UserID); err != nil {
|
||||||
|
constant.SetErrorForResp(err, resp.CommonResp)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
|
||||||
return resp, nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *cacheServer) GetBlackIDListFromCache(_ context.Context, req *pbCache.GetBlackIDListFromCacheReq) (resp *pbCache.GetBlackIDListFromCacheResp, err error) {
|
func (s *cacheServer) GetBlackIDListFromCache(ctx context.Context, req *pbCache.GetBlackIDListFromCacheReq) (resp *pbCache.GetBlackIDListFromCacheResp, err error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
resp = &pbCache.GetBlackIDListFromCacheResp{CommonResp: &sdkws.CommonResp{}}
|
||||||
resp = &pbCache.GetBlackIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||||
blackUserIDList, err := rocksCache.GetBlackListFromCache(req.UserID)
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), nil, "req", req.String(), "resp", resp.String())
|
||||||
|
trace_log.ShowLog(ctx)
|
||||||
|
}()
|
||||||
|
blackUserIDList, err := rocksCache.GetBlackListFromCache(ctx, req.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error())
|
constant.SetErrorForResp(err, resp.CommonResp)
|
||||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
return
|
||||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
|
||||||
return resp, nil
|
|
||||||
}
|
}
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), blackUserIDList)
|
|
||||||
resp.UserIDList = blackUserIDList
|
resp.UserIDList = blackUserIDList
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
return
|
||||||
return resp, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *cacheServer) DelBlackIDListFromCache(_ context.Context, req *pbCache.DelBlackIDListFromCacheReq) (resp *pbCache.DelBlackIDListFromCacheResp, err error) {
|
func (s *cacheServer) DelBlackIDListFromCache(ctx context.Context, req *pbCache.DelBlackIDListFromCacheReq) (resp *pbCache.DelBlackIDListFromCacheResp, err error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
resp = &pbCache.DelBlackIDListFromCacheResp{CommonResp: &sdkws.CommonResp{}}
|
||||||
resp = &pbCache.DelBlackIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||||
if err := rocksCache.DelBlackIDListFromCache(req.UserID); err != nil {
|
defer func() {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.UserID, err.Error())
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), nil, "req", req.String(), "resp", resp.String())
|
||||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
trace_log.ShowLog(ctx)
|
||||||
resp.CommonResp.ErrMsg = err.Error()
|
}()
|
||||||
return resp, nil
|
if err := rocksCache.DelBlackIDListFromCache(ctx, req.UserID); err != nil {
|
||||||
|
constant.SetErrorForResp(err, resp.CommonResp)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *cacheServer) GetGroupMemberIDListFromCache(_ context.Context, req *pbCache.GetGroupMemberIDListFromCacheReq) (resp *pbCache.GetGroupMemberIDListFromCacheResp, err error) {
|
func (s *cacheServer) GetGroupMemberIDListFromCache(ctx context.Context, req *pbCache.GetGroupMemberIDListFromCacheReq) (resp *pbCache.GetGroupMemberIDListFromCacheResp, err error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
|
||||||
resp = &pbCache.GetGroupMemberIDListFromCacheResp{
|
resp = &pbCache.GetGroupMemberIDListFromCacheResp{
|
||||||
CommonResp: &pbCache.CommonResp{},
|
CommonResp: &sdkws.CommonResp{},
|
||||||
}
|
}
|
||||||
userIDList, err := rocksCache.GetGroupMemberIDListFromCache(req.GroupID)
|
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), nil, "req", req.String(), "resp", resp.String())
|
||||||
|
trace_log.ShowLog(ctx)
|
||||||
|
}()
|
||||||
|
userIDList, err := rocksCache.GetGroupMemberIDListFromCache(ctx, req.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberIDListFromCache failed", err.Error())
|
constant.SetErrorForResp(err, resp.CommonResp)
|
||||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
|
||||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
resp.UserIDList = userIDList
|
resp.UserIDList = userIDList
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *cacheServer) DelGroupMemberIDListFromCache(_ context.Context, req *pbCache.DelGroupMemberIDListFromCacheReq) (resp *pbCache.DelGroupMemberIDListFromCacheResp, err error) {
|
func (s *cacheServer) DelGroupMemberIDListFromCache(ctx context.Context, req *pbCache.DelGroupMemberIDListFromCacheReq) (resp *pbCache.DelGroupMemberIDListFromCacheResp, err error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
resp = &pbCache.DelGroupMemberIDListFromCacheResp{CommonResp: &sdkws.CommonResp{}}
|
||||||
resp = &pbCache.DelGroupMemberIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||||
if err := rocksCache.DelGroupMemberIDListFromCache(req.GroupID); err != nil {
|
defer func() {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.GroupID, err.Error())
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), nil, "req", req.String(), "resp", resp.String())
|
||||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
trace_log.ShowLog(ctx)
|
||||||
resp.CommonResp.ErrMsg = err.Error()
|
}()
|
||||||
|
if err := rocksCache.DelGroupMemberIDListFromCache(ctx, req.GroupID); err != nil {
|
||||||
|
constant.SetErrorForResp(err, resp.CommonResp)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@ -49,6 +50,7 @@ var (
|
|||||||
ErrDismissedAlready = ErrInfo{DismissedAlreadyError, "DismissedAlreadyError", ""}
|
ErrDismissedAlready = ErrInfo{DismissedAlreadyError, "DismissedAlreadyError", ""}
|
||||||
ErrOwnerNotAllowedQuit = ErrInfo{OwnerNotAllowedQuitError, "OwnerNotAllowedQuitError", ""}
|
ErrOwnerNotAllowedQuit = ErrInfo{OwnerNotAllowedQuitError, "OwnerNotAllowedQuitError", ""}
|
||||||
ErrRegisteredAlready = ErrInfo{RegisteredAlreadyError, "RegisteredAlreadyError", ""}
|
ErrRegisteredAlready = ErrInfo{RegisteredAlreadyError, "RegisteredAlreadyError", ""}
|
||||||
|
ErrGroupTypeNotSupport = ErrInfo{GroupTypeNotSupport, "", ""}
|
||||||
|
|
||||||
ErrDefaultOther = ErrInfo{DefaultOtherError, "DefaultOtherError", ""}
|
ErrDefaultOther = ErrInfo{DefaultOtherError, "DefaultOtherError", ""}
|
||||||
ErrData = ErrInfo{DataError, "DataError", ""}
|
ErrData = ErrInfo{DataError, "DataError", ""}
|
||||||
@ -102,6 +104,20 @@ func ToAPIErrWithErr(err error) ErrInfo {
|
|||||||
return ErrDefaultOther
|
return ErrDefaultOther
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetErrorForResp(err error, commonResp *sdkws.CommonResp) {
|
||||||
|
errInfo := ToAPIErrWithErr(err)
|
||||||
|
commonResp.ErrCode = errInfo.ErrCode
|
||||||
|
commonResp.ErrMsg = errInfo.ErrMsg
|
||||||
|
commonResp.DetailErrMsg = err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
func CommonResp2Err(resp *sdkws.CommonResp) error {
|
||||||
|
if resp.ErrCode != NoError {
|
||||||
|
return errors.New(fmt.Sprintf("call rpc error, errCode is %d, errMsg is %s, detailErrMsg is %s", resp.ErrCode, resp.ErrMsg, resp.DetailErrMsg))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func Error2CommResp(ctx context.Context, info ErrInfo, detailErrMsg string) *sdkws.CommonResp {
|
func Error2CommResp(ctx context.Context, info ErrInfo, detailErrMsg string) *sdkws.CommonResp {
|
||||||
err := &sdkws.CommonResp{
|
err := &sdkws.CommonResp{
|
||||||
ErrCode: info.ErrCode,
|
ErrCode: info.ErrCode,
|
||||||
@ -166,6 +182,7 @@ const (
|
|||||||
NotInGroupYetError = 93004 //不在群组中
|
NotInGroupYetError = 93004 //不在群组中
|
||||||
DismissedAlreadyError = 93004 //群组已经解散
|
DismissedAlreadyError = 93004 //群组已经解散
|
||||||
OwnerNotAllowedQuitError = 93004 //群主不能退群
|
OwnerNotAllowedQuitError = 93004 //群主不能退群
|
||||||
|
GroupTypeNotSupport = 93005
|
||||||
)
|
)
|
||||||
|
|
||||||
// 用户错误码
|
// 用户错误码
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
|
"Open_IM/pkg/common/trace_log"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -69,7 +70,7 @@ func DelKeys() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFriendIDListFromCache(userID string) ([]string, error) {
|
func GetFriendIDListFromCache(ctx context.Context, userID string) (friendIDList []string, err error) {
|
||||||
getFriendIDList := func() (string, error) {
|
getFriendIDList := func() (string, error) {
|
||||||
friendIDList, err := imdb.GetFriendIDListByUserID(userID)
|
friendIDList, err := imdb.GetFriendIDListByUserID(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -81,21 +82,25 @@ func GetFriendIDListFromCache(userID string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "friendIDList", friendIDList)
|
||||||
|
}()
|
||||||
friendIDListStr, err := db.DB.Rc.Fetch(friendRelationCache+userID, time.Second*30*60, getFriendIDList)
|
friendIDListStr, err := db.DB.Rc.Fetch(friendRelationCache+userID, time.Second*30*60, getFriendIDList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "")
|
return nil, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
var friendIDList []string
|
|
||||||
err = json.Unmarshal([]byte(friendIDListStr), &friendIDList)
|
err = json.Unmarshal([]byte(friendIDListStr), &friendIDList)
|
||||||
return friendIDList, utils.Wrap(err, "")
|
return friendIDList, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelFriendIDListFromCache(userID string) error {
|
func DelFriendIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||||
err := db.DB.Rc.TagAsDeleted(friendRelationCache + userID)
|
defer func() {
|
||||||
return err
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||||
|
}()
|
||||||
|
return db.DB.Rc.TagAsDeleted(friendRelationCache + userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBlackListFromCache(userID string) ([]string, error) {
|
func GetBlackListFromCache(ctx context.Context, userID string) (blackIDList []string, err error) {
|
||||||
getBlackIDList := func() (string, error) {
|
getBlackIDList := func() (string, error) {
|
||||||
blackIDList, err := imdb.GetBlackIDListByUserID(userID)
|
blackIDList, err := imdb.GetBlackIDListByUserID(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -107,20 +112,25 @@ func GetBlackListFromCache(userID string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "blackIDList", blackIDList)
|
||||||
|
}()
|
||||||
blackIDListStr, err := db.DB.Rc.Fetch(blackListCache+userID, time.Second*30*60, getBlackIDList)
|
blackIDListStr, err := db.DB.Rc.Fetch(blackListCache+userID, time.Second*30*60, getBlackIDList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "")
|
return nil, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
var blackIDList []string
|
|
||||||
err = json.Unmarshal([]byte(blackIDListStr), &blackIDList)
|
err = json.Unmarshal([]byte(blackIDListStr), &blackIDList)
|
||||||
return blackIDList, utils.Wrap(err, "")
|
return blackIDList, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelBlackIDListFromCache(userID string) error {
|
func DelBlackIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "ctx", ctx)
|
||||||
|
}()
|
||||||
return db.DB.Rc.TagAsDeleted(blackListCache + userID)
|
return db.DB.Rc.TagAsDeleted(blackListCache + userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetJoinedGroupIDListFromCache(userID string) ([]string, error) {
|
func GetJoinedGroupIDListFromCache(ctx context.Context, userID string) (joinedGroupList []string, err error) {
|
||||||
getJoinedGroupIDList := func() (string, error) {
|
getJoinedGroupIDList := func() (string, error) {
|
||||||
joinedGroupList, err := imdb.GetJoinedGroupIDListByUserID(userID)
|
joinedGroupList, err := imdb.GetJoinedGroupIDListByUserID(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -132,22 +142,27 @@ func GetJoinedGroupIDListFromCache(userID string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "joinedGroupList", joinedGroupList)
|
||||||
|
}()
|
||||||
joinedGroupIDListStr, err := db.DB.Rc.Fetch(joinedGroupListCache+userID, time.Second*30*60, getJoinedGroupIDList)
|
joinedGroupIDListStr, err := db.DB.Rc.Fetch(joinedGroupListCache+userID, time.Second*30*60, getJoinedGroupIDList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "")
|
return nil, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
var joinedGroupList []string
|
|
||||||
err = json.Unmarshal([]byte(joinedGroupIDListStr), &joinedGroupList)
|
err = json.Unmarshal([]byte(joinedGroupIDListStr), &joinedGroupList)
|
||||||
return joinedGroupList, utils.Wrap(err, "")
|
return joinedGroupList, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelJoinedGroupIDListFromCache(userID string) error {
|
func DelJoinedGroupIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||||
|
}()
|
||||||
return db.DB.Rc.TagAsDeleted(joinedGroupListCache + userID)
|
return db.DB.Rc.TagAsDeleted(joinedGroupListCache + userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGroupMemberIDListFromCache(groupID string) ([]string, error) {
|
func GetGroupMemberIDListFromCache(ctx context.Context, groupID string) (groupMemberIDList []string, err error) {
|
||||||
f := func() (string, error) {
|
f := func() (string, error) {
|
||||||
groupInfo, err := GetGroupInfoFromCache(groupID)
|
groupInfo, err := GetGroupInfoFromCache(ctx, groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", utils.Wrap(err, "GetGroupInfoFromCache failed")
|
return "", utils.Wrap(err, "GetGroupInfoFromCache failed")
|
||||||
}
|
}
|
||||||
@ -170,21 +185,25 @@ func GetGroupMemberIDListFromCache(groupID string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMemberIDList", groupMemberIDList)
|
||||||
|
}()
|
||||||
groupIDListStr, err := db.DB.Rc.Fetch(groupCache+groupID, time.Second*30*60, f)
|
groupIDListStr, err := db.DB.Rc.Fetch(groupCache+groupID, time.Second*30*60, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "")
|
return nil, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
var groupMemberIDList []string
|
|
||||||
err = json.Unmarshal([]byte(groupIDListStr), &groupMemberIDList)
|
err = json.Unmarshal([]byte(groupIDListStr), &groupMemberIDList)
|
||||||
return groupMemberIDList, utils.Wrap(err, "")
|
return groupMemberIDList, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelGroupMemberIDListFromCache(groupID string) error {
|
func DelGroupMemberIDListFromCache(ctx context.Context, groupID string) (err error) {
|
||||||
err := db.DB.Rc.TagAsDeleted(groupCache + groupID)
|
defer func() {
|
||||||
return err
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||||
|
}()
|
||||||
|
return db.DB.Rc.TagAsDeleted(groupCache + groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserInfoFromCache(userID string) (*imdb.User, error) {
|
func GetUserInfoFromCache(ctx context.Context, userID string) (userInfo *imdb.User, err error) {
|
||||||
getUserInfo := func() (string, error) {
|
getUserInfo := func() (string, error) {
|
||||||
userInfo, err := imdb.GetUserByUserID(userID)
|
userInfo, err := imdb.GetUserByUserID(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -196,19 +215,22 @@ func GetUserInfoFromCache(userID string) (*imdb.User, error) {
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "userInfo", *userInfo)
|
||||||
|
}()
|
||||||
userInfoStr, err := db.DB.Rc.Fetch(userInfoCache+userID, time.Second*30*60, getUserInfo)
|
userInfoStr, err := db.DB.Rc.Fetch(userInfoCache+userID, time.Second*30*60, getUserInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "")
|
return nil, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
userInfo := &imdb.User{}
|
userInfo = &imdb.User{}
|
||||||
err = json.Unmarshal([]byte(userInfoStr), userInfo)
|
err = json.Unmarshal([]byte(userInfoStr), userInfo)
|
||||||
return userInfo, utils.Wrap(err, "")
|
return userInfo, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserInfoFromCacheBatch(userIDs []string) ([]*imdb.User, error) {
|
func GetUserInfoFromCacheBatch(ctx context.Context, userIDs []string) ([]*imdb.User, error) {
|
||||||
var users []*imdb.User
|
var users []*imdb.User
|
||||||
for _, userID := range userIDs {
|
for _, userID := range userIDs {
|
||||||
user, err := GetUserInfoFromCache(userID)
|
user, err := GetUserInfoFromCache(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -217,11 +239,14 @@ func GetUserInfoFromCacheBatch(userIDs []string) ([]*imdb.User, error) {
|
|||||||
return users, nil
|
return users, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelUserInfoFromCache(userID string) error {
|
func DelUserInfoFromCache(ctx context.Context, userID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||||
|
}()
|
||||||
return db.DB.Rc.TagAsDeleted(userInfoCache + userID)
|
return db.DB.Rc.TagAsDeleted(userInfoCache + userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGroupMemberInfoFromCache(groupID, userID string) (*imdb.GroupMember, error) {
|
func GetGroupMemberInfoFromCache(ctx context.Context, groupID, userID string) (groupMember *imdb.GroupMember, err error) {
|
||||||
getGroupMemberInfo := func() (string, error) {
|
getGroupMemberInfo := func() (string, error) {
|
||||||
groupMemberInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
|
groupMemberInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -233,21 +258,30 @@ func GetGroupMemberInfoFromCache(groupID, userID string) (*imdb.GroupMember, err
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupMember", *groupMember)
|
||||||
|
}()
|
||||||
groupMemberInfoStr, err := db.DB.Rc.Fetch(groupMemberInfoCache+groupID+"-"+userID, time.Second*30*60, getGroupMemberInfo)
|
groupMemberInfoStr, err := db.DB.Rc.Fetch(groupMemberInfoCache+groupID+"-"+userID, time.Second*30*60, getGroupMemberInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "")
|
return nil, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
groupMember := &imdb.GroupMember{}
|
groupMember = &imdb.GroupMember{}
|
||||||
err = json.Unmarshal([]byte(groupMemberInfoStr), groupMember)
|
err = json.Unmarshal([]byte(groupMemberInfoStr), groupMember)
|
||||||
return groupMember, utils.Wrap(err, "")
|
return groupMember, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelGroupMemberInfoFromCache(groupID, userID string) error {
|
func DelGroupMemberInfoFromCache(ctx context.Context, groupID, userID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID)
|
||||||
|
}()
|
||||||
return db.DB.Rc.TagAsDeleted(groupMemberInfoCache + groupID + "-" + userID)
|
return db.DB.Rc.TagAsDeleted(groupMemberInfoCache + groupID + "-" + userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGroupMembersInfoFromCache(count, offset int32, groupID string) ([]*imdb.GroupMember, error) {
|
func GetGroupMembersInfoFromCache(ctx context.Context, count, offset int32, groupID string) (groupMembers []*imdb.GroupMember, err error) {
|
||||||
groupMemberIDList, err := GetGroupMemberIDListFromCache(groupID)
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "count", count, "offset", offset, "groupID", groupID, "groupMember", groupMembers)
|
||||||
|
}()
|
||||||
|
groupMemberIDList, err := GetGroupMemberIDListFromCache(ctx, groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -280,17 +314,20 @@ func GetGroupMembersInfoFromCache(count, offset int32, groupID string) ([]*imdb.
|
|||||||
}
|
}
|
||||||
//log.NewDebug("", utils.GetSelfFuncName(), "ID list: ", groupMemberIDList)
|
//log.NewDebug("", utils.GetSelfFuncName(), "ID list: ", groupMemberIDList)
|
||||||
for _, userID := range groupMemberIDList {
|
for _, userID := range groupMemberIDList {
|
||||||
groupMembers, err := GetGroupMemberInfoFromCache(groupID, userID)
|
groupMember, err := GetGroupMemberInfoFromCache(ctx, groupID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("", utils.GetSelfFuncName(), err.Error(), groupID, userID)
|
log.NewError("", utils.GetSelfFuncName(), err.Error(), groupID, userID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
groupMemberList = append(groupMemberList, groupMembers)
|
groupMembers = append(groupMembers, groupMember)
|
||||||
}
|
}
|
||||||
return groupMemberList, nil
|
return groupMemberList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllGroupMembersInfoFromCache(groupID string) ([]*imdb.GroupMember, error) {
|
func GetAllGroupMembersInfoFromCache(ctx context.Context, groupID string) (groupMembers []*imdb.GroupMember, err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMembers", groupMembers)
|
||||||
|
}()
|
||||||
getGroupMemberInfo := func() (string, error) {
|
getGroupMemberInfo := func() (string, error) {
|
||||||
groupMembers, err := imdb.GetGroupMemberListByGroupID(groupID)
|
groupMembers, err := imdb.GetGroupMemberListByGroupID(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -306,16 +343,18 @@ func GetAllGroupMembersInfoFromCache(groupID string) ([]*imdb.GroupMember, error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "")
|
return nil, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
var groupMembers []*imdb.GroupMember
|
|
||||||
err = json.Unmarshal([]byte(groupMembersStr), &groupMembers)
|
err = json.Unmarshal([]byte(groupMembersStr), &groupMembers)
|
||||||
return groupMembers, utils.Wrap(err, "")
|
return groupMembers, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelAllGroupMembersInfoFromCache(groupID string) error {
|
func DelAllGroupMembersInfoFromCache(ctx context.Context, groupID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||||
|
}()
|
||||||
return db.DB.Rc.TagAsDeleted(groupAllMemberInfoCache + groupID)
|
return db.DB.Rc.TagAsDeleted(groupAllMemberInfoCache + groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGroupInfoFromCache(ctx context.Context, groupID string) (*imdb.Group, error) {
|
func GetGroupInfoFromCache(ctx context.Context, groupID string) (groupInfo *imdb.Group, err error) {
|
||||||
getGroupInfo := func() (string, error) {
|
getGroupInfo := func() (string, error) {
|
||||||
groupInfo, err := imdb.GetGroupInfoByGroupID(groupID)
|
groupInfo, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -327,20 +366,25 @@ func GetGroupInfoFromCache(ctx context.Context, groupID string) (*imdb.Group, er
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupInfo", *groupInfo)
|
||||||
|
}()
|
||||||
groupInfoStr, err := db.DB.Rc.Fetch(groupInfoCache+groupID, time.Second*30*60, getGroupInfo)
|
groupInfoStr, err := db.DB.Rc.Fetch(groupInfoCache+groupID, time.Second*30*60, getGroupInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "")
|
return nil, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
groupInfo := &imdb.Group{}
|
|
||||||
err = json.Unmarshal([]byte(groupInfoStr), groupInfo)
|
err = json.Unmarshal([]byte(groupInfoStr), groupInfo)
|
||||||
return groupInfo, utils.Wrap(err, "")
|
return groupInfo, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelGroupInfoFromCache(groupID string) error {
|
func DelGroupInfoFromCache(ctx context.Context, groupID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||||
|
}()
|
||||||
return db.DB.Rc.TagAsDeleted(groupInfoCache + groupID)
|
return db.DB.Rc.TagAsDeleted(groupInfoCache + groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllFriendsInfoFromCache(userID string) ([]*imdb.Friend, error) {
|
func GetAllFriendsInfoFromCache(ctx context.Context, userID string) (friends []*imdb.Friend, err error) {
|
||||||
getAllFriendInfo := func() (string, error) {
|
getAllFriendInfo := func() (string, error) {
|
||||||
friendInfoList, err := imdb.GetFriendListByUserID(userID)
|
friendInfoList, err := imdb.GetFriendListByUserID(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -352,16 +396,21 @@ func GetAllFriendsInfoFromCache(userID string) ([]*imdb.Friend, error) {
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "friends", friends)
|
||||||
|
}()
|
||||||
allFriendInfoStr, err := db.DB.Rc.Fetch(allFriendInfoCache+userID, time.Second*30*60, getAllFriendInfo)
|
allFriendInfoStr, err := db.DB.Rc.Fetch(allFriendInfoCache+userID, time.Second*30*60, getAllFriendInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "")
|
return nil, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
var friendInfoList []*imdb.Friend
|
err = json.Unmarshal([]byte(allFriendInfoStr), &friends)
|
||||||
err = json.Unmarshal([]byte(allFriendInfoStr), &friendInfoList)
|
return friends, utils.Wrap(err, "")
|
||||||
return friendInfoList, utils.Wrap(err, "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelAllFriendsInfoFromCache(userID string) error {
|
func DelAllFriendsInfoFromCache(ctx context.Context, userID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||||
|
}()
|
||||||
return db.DB.Rc.TagAsDeleted(allFriendInfoCache + userID)
|
return db.DB.Rc.TagAsDeleted(allFriendInfoCache + userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +464,7 @@ func DelAllDepartmentMembersFromCache() error {
|
|||||||
return db.DB.Rc.TagAsDeleted(allDepartmentMemberCache)
|
return db.DB.Rc.TagAsDeleted(allDepartmentMemberCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetJoinedSuperGroupListFromCache(userID string) ([]string, error) {
|
func GetJoinedSuperGroupListFromCache(ctx context.Context, userID string) (joinedSuperGroupIDs []string, err error) {
|
||||||
getJoinedSuperGroupIDList := func() (string, error) {
|
getJoinedSuperGroupIDList := func() (string, error) {
|
||||||
userToSuperGroup, err := db.DB.GetSuperGroupByUserID(userID)
|
userToSuperGroup, err := db.DB.GetSuperGroupByUserID(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -427,30 +476,34 @@ func GetJoinedSuperGroupListFromCache(userID string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "joinedSuperGroupIDs", joinedSuperGroupIDs)
|
||||||
|
}()
|
||||||
joinedSuperGroupListStr, err := db.DB.Rc.Fetch(joinedSuperGroupListCache+userID, time.Second*30*60, getJoinedSuperGroupIDList)
|
joinedSuperGroupListStr, err := db.DB.Rc.Fetch(joinedSuperGroupListCache+userID, time.Second*30*60, getJoinedSuperGroupIDList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var joinedSuperGroupList []string
|
err = json.Unmarshal([]byte(joinedSuperGroupListStr), &joinedSuperGroupIDs)
|
||||||
err = json.Unmarshal([]byte(joinedSuperGroupListStr), &joinedSuperGroupList)
|
return joinedSuperGroupIDs, utils.Wrap(err, "")
|
||||||
return joinedSuperGroupList, utils.Wrap(err, "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelJoinedSuperGroupIDListFromCache(userID string) error {
|
func DelJoinedSuperGroupIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||||
err := db.DB.Rc.TagAsDeleted(joinedSuperGroupListCache + userID)
|
defer func() {
|
||||||
return err
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||||
|
}()
|
||||||
|
return db.DB.Rc.TagAsDeleted(joinedSuperGroupListCache + userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGroupMemberListHashFromCache(groupID string) (uint64, error) {
|
func GetGroupMemberListHashFromCache(ctx context.Context, groupID string) (hashCodeUint64 uint64, err error) {
|
||||||
generateHash := func() (string, error) {
|
generateHash := func() (string, error) {
|
||||||
groupInfo, err := GetGroupInfoFromCache(groupID)
|
groupInfo, err := GetGroupInfoFromCache(ctx, groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "0", utils.Wrap(err, "GetGroupInfoFromCache failed")
|
return "0", utils.Wrap(err, "GetGroupInfoFromCache failed")
|
||||||
}
|
}
|
||||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||||
return "0", nil
|
return "0", nil
|
||||||
}
|
}
|
||||||
groupMemberIDList, err := GetGroupMemberIDListFromCache(groupID)
|
groupMemberIDList, err := GetGroupMemberIDListFromCache(ctx, groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", utils.Wrap(err, "GetGroupMemberIDListFromCache failed")
|
return "", utils.Wrap(err, "GetGroupMemberIDListFromCache failed")
|
||||||
}
|
}
|
||||||
@ -463,20 +516,25 @@ func GetGroupMemberListHashFromCache(groupID string) (uint64, error) {
|
|||||||
bi.SetString(utils.Md5(all)[0:8], 16)
|
bi.SetString(utils.Md5(all)[0:8], 16)
|
||||||
return strconv.Itoa(int(bi.Uint64())), nil
|
return strconv.Itoa(int(bi.Uint64())), nil
|
||||||
}
|
}
|
||||||
hashCode, err := db.DB.Rc.Fetch(groupMemberListHashCache+groupID, time.Second*30*60, generateHash)
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "hashCodeUint64", hashCodeUint64)
|
||||||
|
}()
|
||||||
|
hashCodeStr, err := db.DB.Rc.Fetch(groupMemberListHashCache+groupID, time.Second*30*60, generateHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, utils.Wrap(err, "fetch failed")
|
return 0, utils.Wrap(err, "fetch failed")
|
||||||
}
|
}
|
||||||
hashCodeUint64, err := strconv.Atoi(hashCode)
|
hashCode, err := strconv.Atoi(hashCodeStr)
|
||||||
return uint64(hashCodeUint64), err
|
return uint64(hashCode), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelGroupMemberListHashFromCache(groupID string) error {
|
func DelGroupMemberListHashFromCache(ctx context.Context, groupID string) (err error) {
|
||||||
err := db.DB.Rc.TagAsDeleted(groupMemberListHashCache + groupID)
|
defer func() {
|
||||||
return err
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||||
|
}()
|
||||||
|
return db.DB.Rc.TagAsDeleted(groupMemberListHashCache + groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGroupMemberNumFromCache(groupID string) (int64, error) {
|
func GetGroupMemberNumFromCache(ctx context.Context, groupID string) (num int, err error) {
|
||||||
getGroupMemberNum := func() (string, error) {
|
getGroupMemberNum := func() (string, error) {
|
||||||
num, err := imdb.GetGroupMemberNumByGroupID(groupID)
|
num, err := imdb.GetGroupMemberNumByGroupID(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -484,19 +542,24 @@ func GetGroupMemberNumFromCache(groupID string) (int64, error) {
|
|||||||
}
|
}
|
||||||
return strconv.Itoa(int(num)), nil
|
return strconv.Itoa(int(num)), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "num", num)
|
||||||
|
}()
|
||||||
groupMember, err := db.DB.Rc.Fetch(groupMemberNumCache+groupID, time.Second*30*60, getGroupMemberNum)
|
groupMember, err := db.DB.Rc.Fetch(groupMemberNumCache+groupID, time.Second*30*60, getGroupMemberNum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, utils.Wrap(err, "")
|
return 0, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
num, err := strconv.Atoi(groupMember)
|
return strconv.Atoi(groupMember)
|
||||||
return int64(num), err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelGroupMemberNumFromCache(groupID string) error {
|
func DelGroupMemberNumFromCache(ctx context.Context, groupID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||||
|
}()
|
||||||
return db.DB.Rc.TagAsDeleted(groupMemberNumCache + groupID)
|
return db.DB.Rc.TagAsDeleted(groupMemberNumCache + groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserConversationIDListFromCache(userID string) ([]string, error) {
|
func GetUserConversationIDListFromCache(ctx context.Context, userID string) (conversationIDs []string, err error) {
|
||||||
getConversationIDList := func() (string, error) {
|
getConversationIDList := func() (string, error) {
|
||||||
conversationIDList, err := imdb.GetConversationIDListByUserID(userID)
|
conversationIDList, err := imdb.GetConversationIDListByUserID(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -509,20 +572,25 @@ func GetUserConversationIDListFromCache(userID string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID, "conversationIDs", conversationIDs)
|
||||||
|
}()
|
||||||
conversationIDListStr, err := db.DB.Rc.Fetch(conversationIDListCache+userID, time.Second*30*60, getConversationIDList)
|
conversationIDListStr, err := db.DB.Rc.Fetch(conversationIDListCache+userID, time.Second*30*60, getConversationIDList)
|
||||||
var conversationIDList []string
|
err = json.Unmarshal([]byte(conversationIDListStr), &conversationIDs)
|
||||||
err = json.Unmarshal([]byte(conversationIDListStr), &conversationIDList)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "")
|
return nil, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
return conversationIDList, nil
|
return conversationIDs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelUserConversationIDListFromCache(userID string) error {
|
func DelUserConversationIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||||
|
}()
|
||||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationIDListCache+userID), "DelUserConversationIDListFromCache err")
|
return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationIDListCache+userID), "DelUserConversationIDListFromCache err")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConversationFromCache(ownerUserID, conversationID string) (*imdb.Conversation, error) {
|
func GetConversationFromCache(ctx context.Context, ownerUserID, conversationID string) (conversation *imdb.Conversation, err error) {
|
||||||
getConversation := func() (string, error) {
|
getConversation := func() (string, error) {
|
||||||
conversation, err := imdb.GetConversation(ownerUserID, conversationID)
|
conversation, err := imdb.GetConversation(ownerUserID, conversationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -534,39 +602,44 @@ func GetConversationFromCache(ownerUserID, conversationID string) (*imdb.Convers
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationID", conversationID, "conversation", *conversation)
|
||||||
|
}()
|
||||||
conversationStr, err := db.DB.Rc.Fetch(conversationCache+ownerUserID+":"+conversationID, time.Second*30*60, getConversation)
|
conversationStr, err := db.DB.Rc.Fetch(conversationCache+ownerUserID+":"+conversationID, time.Second*30*60, getConversation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "Fetch failed")
|
return nil, utils.Wrap(err, "Fetch failed")
|
||||||
}
|
}
|
||||||
conversation := imdb.Conversation{}
|
conversation = &imdb.Conversation{}
|
||||||
err = json.Unmarshal([]byte(conversationStr), &conversation)
|
err = json.Unmarshal([]byte(conversationStr), &conversation)
|
||||||
if err != nil {
|
return conversation, utils.Wrap(err, "Unmarshal failed")
|
||||||
return nil, utils.Wrap(err, "Unmarshal failed")
|
|
||||||
}
|
|
||||||
return &conversation, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConversationsFromCache(ownerUserID string, conversationIDList []string) ([]imdb.Conversation, error) {
|
func GetConversationsFromCache(ctx context.Context, ownerUserID string, conversationIDs []string) (conversations []imdb.Conversation, err error) {
|
||||||
var conversationList []imdb.Conversation
|
defer func() {
|
||||||
for _, conversationID := range conversationIDList {
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationIDs", conversationIDs, "conversations", conversations)
|
||||||
conversation, err := GetConversationFromCache(ownerUserID, conversationID)
|
}()
|
||||||
|
for _, conversationID := range conversationIDs {
|
||||||
|
conversation, err := GetConversationFromCache(ctx, ownerUserID, conversationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "GetConversationFromCache failed")
|
return nil, utils.Wrap(err, "GetConversationFromCache failed")
|
||||||
}
|
}
|
||||||
conversationList = append(conversationList, *conversation)
|
conversations = append(conversations, *conversation)
|
||||||
}
|
}
|
||||||
return conversationList, nil
|
return conversations, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserAllConversationList(ownerUserID string) ([]imdb.Conversation, error) {
|
func GetUserAllConversationList(ctx context.Context, ownerUserID string) (conversations []imdb.Conversation, err error) {
|
||||||
IDList, err := GetUserConversationIDListFromCache(ownerUserID)
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversations", conversations)
|
||||||
|
}()
|
||||||
|
IDList, err := GetUserConversationIDListFromCache(ctx, ownerUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var conversationList []imdb.Conversation
|
var conversationList []imdb.Conversation
|
||||||
log.NewDebug("", utils.GetSelfFuncName(), IDList)
|
log.NewDebug("", utils.GetSelfFuncName(), IDList)
|
||||||
for _, conversationID := range IDList {
|
for _, conversationID := range IDList {
|
||||||
conversation, err := GetConversationFromCache(ownerUserID, conversationID)
|
conversation, err := GetConversationFromCache(ctx, ownerUserID, conversationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "GetConversationFromCache failed")
|
return nil, utils.Wrap(err, "GetConversationFromCache failed")
|
||||||
}
|
}
|
||||||
@ -575,11 +648,14 @@ func GetUserAllConversationList(ownerUserID string) ([]imdb.Conversation, error)
|
|||||||
return conversationList, nil
|
return conversationList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelConversationFromCache(ownerUserID, conversationID string) error {
|
func DelConversationFromCache(ctx context.Context, ownerUserID, conversationID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationID", conversationID)
|
||||||
|
}()
|
||||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationCache+ownerUserID+":"+conversationID), "DelConversationFromCache err")
|
return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationCache+ownerUserID+":"+conversationID), "DelConversationFromCache err")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetExtendMsg(sourceID string, sessionType int32, clientMsgID string, firstModifyTime int64) (*db.ExtendMsg, error) {
|
func GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, firstModifyTime int64) (extendMsg *db.ExtendMsg, err error) {
|
||||||
getExtendMsg := func() (string, error) {
|
getExtendMsg := func() (string, error) {
|
||||||
extendMsg, err := db.DB.GetExtendMsg(sourceID, sessionType, clientMsgID, firstModifyTime)
|
extendMsg, err := db.DB.GetExtendMsg(sourceID, sessionType, clientMsgID, firstModifyTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -591,19 +667,22 @@ func GetExtendMsg(sourceID string, sessionType int32, clientMsgID string, firstM
|
|||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "sourceID", sourceID, "sessionType",
|
||||||
|
sessionType, "clientMsgID", clientMsgID, "firstModifyTime", firstModifyTime, "extendMsg", extendMsg)
|
||||||
|
}()
|
||||||
extendMsgStr, err := db.DB.Rc.Fetch(extendMsgCache+clientMsgID, time.Second*30*60, getExtendMsg)
|
extendMsgStr, err := db.DB.Rc.Fetch(extendMsgCache+clientMsgID, time.Second*30*60, getExtendMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.Wrap(err, "Fetch failed")
|
return nil, utils.Wrap(err, "Fetch failed")
|
||||||
}
|
}
|
||||||
extendMsg := &db.ExtendMsg{}
|
extendMsg = &db.ExtendMsg{}
|
||||||
err = json.Unmarshal([]byte(extendMsgStr), extendMsg)
|
err = json.Unmarshal([]byte(extendMsgStr), extendMsg)
|
||||||
if err != nil {
|
return extendMsg, utils.Wrap(err, "Unmarshal failed")
|
||||||
return nil, utils.Wrap(err, "Unmarshal failed")
|
|
||||||
}
|
|
||||||
return extendMsg, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelExtendMsg(ID string, index int32, clientMsgID string) error {
|
func DelExtendMsg(ctx context.Context, clientMsgID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "clientMsgID", clientMsgID)
|
||||||
|
}()
|
||||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(extendMsgCache+clientMsgID), "DelExtendMsg err")
|
return utils.Wrap(db.DB.Rc.TagAsDeleted(extendMsgCache+clientMsgID), "DelExtendMsg err")
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,10 @@ func SetOperationID(ctx context.Context, operationID string) {
|
|||||||
ctx.Value(TraceLogKey).(*ApiInfo).OperationID = operationID
|
ctx.Value(TraceLogKey).(*ApiInfo).OperationID = operationID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetOperationID(ctx context.Context) string {
|
||||||
|
return ctx.Value(TraceLogKey).(*ApiInfo).OperationID
|
||||||
|
}
|
||||||
|
|
||||||
func ShowLog(ctx context.Context) {
|
func ShowLog(ctx context.Context) {
|
||||||
t := ctx.Value(TraceLogKey).(*ApiInfo)
|
t := ctx.Value(TraceLogKey).(*ApiInfo)
|
||||||
if ctx.Value(TraceLogKey).(*ApiInfo).GinCtx != nil {
|
if ctx.Value(TraceLogKey).(*ApiInfo).GinCtx != nil {
|
||||||
|
1399
pkg/proto/cache/cache.pb.go
vendored
1399
pkg/proto/cache/cache.pb.go
vendored
File diff suppressed because it is too large
Load Diff
17
pkg/proto/cache/cache.proto
vendored
17
pkg/proto/cache/cache.proto
vendored
@ -1,11 +1,8 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
import "Open-IM-Server/pkg/proto/sdk_ws/ws.proto";
|
||||||
option go_package = "Open_IM/pkg/proto/cache;cache";
|
option go_package = "Open_IM/pkg/proto/cache;cache";
|
||||||
package cache;
|
package cache;
|
||||||
|
|
||||||
message CommonResp{
|
|
||||||
int32 errCode = 1;
|
|
||||||
string errMsg = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetFriendIDListFromCacheReq {
|
message GetFriendIDListFromCacheReq {
|
||||||
string userID = 1;
|
string userID = 1;
|
||||||
@ -14,7 +11,7 @@ message GetFriendIDListFromCacheReq {
|
|||||||
|
|
||||||
message GetFriendIDListFromCacheResp {
|
message GetFriendIDListFromCacheResp {
|
||||||
repeated string userIDList = 1;
|
repeated string userIDList = 1;
|
||||||
CommonResp commonResp = 2;
|
server_api_params.CommonResp commonResp = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DelFriendIDListFromCacheReq {
|
message DelFriendIDListFromCacheReq {
|
||||||
@ -23,7 +20,7 @@ message DelFriendIDListFromCacheReq {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message DelFriendIDListFromCacheResp {
|
message DelFriendIDListFromCacheResp {
|
||||||
CommonResp commonResp = 1;
|
server_api_params.CommonResp commonResp = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetBlackIDListFromCacheReq {
|
message GetBlackIDListFromCacheReq {
|
||||||
@ -33,7 +30,7 @@ message GetBlackIDListFromCacheReq {
|
|||||||
|
|
||||||
message GetBlackIDListFromCacheResp {
|
message GetBlackIDListFromCacheResp {
|
||||||
repeated string userIDList = 1;
|
repeated string userIDList = 1;
|
||||||
CommonResp commonResp = 2;
|
server_api_params.CommonResp commonResp = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DelBlackIDListFromCacheReq {
|
message DelBlackIDListFromCacheReq {
|
||||||
@ -42,7 +39,7 @@ message DelBlackIDListFromCacheReq {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message DelBlackIDListFromCacheResp {
|
message DelBlackIDListFromCacheResp {
|
||||||
CommonResp commonResp = 1;
|
server_api_params.CommonResp commonResp = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetGroupMemberIDListFromCacheReq {
|
message GetGroupMemberIDListFromCacheReq {
|
||||||
@ -51,7 +48,7 @@ message GetGroupMemberIDListFromCacheReq {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message GetGroupMemberIDListFromCacheResp {
|
message GetGroupMemberIDListFromCacheResp {
|
||||||
CommonResp commonResp = 1;
|
server_api_params.CommonResp commonResp = 1;
|
||||||
repeated string userIDList = 2;
|
repeated string userIDList = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +58,7 @@ message DelGroupMemberIDListFromCacheReq {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message DelGroupMemberIDListFromCacheResp {
|
message DelGroupMemberIDListFromCacheResp {
|
||||||
CommonResp commonResp = 1;
|
server_api_params.CommonResp commonResp = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
service cache{
|
service cache{
|
||||||
|
@ -11,12 +11,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetConn(ctx context.Context, operationID, serviceName string) (conn *grpc.ClientConn, err error) {
|
func GetConn(ctx context.Context, serviceName string) (conn *grpc.ClientConn, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
trace_log.SetContextInfo(ctx, "GetConn", err, "serviceName", serviceName)
|
trace_log.SetContextInfo(ctx, "GetConn", err, "serviceName", serviceName)
|
||||||
}()
|
}()
|
||||||
conn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","),
|
conn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","),
|
||||||
serviceName, operationID, config.Config.Etcd.UserName, config.Config.Etcd.Password)
|
serviceName, trace_log.GetOperationID(ctx), config.Config.Etcd.UserName, config.Config.Etcd.Password)
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return nil, constant.ErrRpcConn
|
return nil, constant.ErrRpcConn
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user