mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-03 00:25:59 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
Vendored
+297
-15
@@ -1,36 +1,92 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/unrelation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/dtm-labs/rockscache"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"math/big"
|
||||
"sort"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const GroupExpireTime = time.Second * 60 * 60 * 12
|
||||
const groupInfoCacheKey = "GROUP_INFO_CACHE:"
|
||||
const (
|
||||
groupExpireTime = time.Second * 60 * 60 * 12
|
||||
groupInfoKey = "GROUP_INFO:"
|
||||
groupMemberIDsKey = "GROUP_MEMBER_IDS:"
|
||||
groupMembersHashKey = "GROUP_MEMBERS_HASH:"
|
||||
groupMemberInfoKey = "GROUP_MEMBER_INFO:"
|
||||
joinedSuperGroupsKey = "JOIN_SUPER_GROUPS:"
|
||||
joinedGroupsKey = "JOIN_GROUPS_KEY:"
|
||||
groupMemberNumKey = "GROUP_MEMBER_NUM_CACHE:"
|
||||
)
|
||||
|
||||
type GroupCache struct {
|
||||
group *relation.Group
|
||||
groupMember *relation.GroupMember
|
||||
groupRequest *relation.GroupRequest
|
||||
mongoDB *unrelation.SuperGroupMgoDB
|
||||
expireTime time.Duration
|
||||
redisClient *RedisClient
|
||||
rcClient *rockscache.Client
|
||||
|
||||
//local cache
|
||||
cacheGroupMtx sync.RWMutex
|
||||
cacheGroupMemberUserIDs map[string]*GroupMemberIDsHash
|
||||
}
|
||||
|
||||
func NewGroupCache(rdb redis.UniversalClient, groupDB *relation.Group, groupMemberDB *relation.GroupMember, groupRequestDB *relation.GroupRequest, opts rockscache.Options) *GroupCache {
|
||||
return &GroupCache{rcClient: rockscache.NewClient(rdb, opts), expireTime: GroupExpireTime, group: groupDB, groupMember: groupMemberDB, groupRequest: groupRequestDB, redisClient: NewRedisClient(rdb)}
|
||||
type GroupMemberIDsHash struct {
|
||||
MemberListHash uint64
|
||||
UserIDs []string
|
||||
}
|
||||
|
||||
func NewGroupCache(rdb redis.UniversalClient, groupDB *relation.Group, groupMemberDB *relation.GroupMember, groupRequestDB *relation.GroupRequest, mongoClient *unrelation.SuperGroupMgoDB, opts rockscache.Options) *GroupCache {
|
||||
return &GroupCache{rcClient: rockscache.NewClient(rdb, opts), expireTime: groupExpireTime,
|
||||
group: groupDB, groupMember: groupMemberDB, groupRequest: groupRequestDB, redisClient: NewRedisClient(rdb),
|
||||
mongoDB: mongoClient, cacheGroupMemberUserIDs: make(map[string]*GroupMemberIDsHash, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GroupCache) getRedisClient() *RedisClient {
|
||||
return g.redisClient
|
||||
}
|
||||
|
||||
func (g *GroupCache) getGroupInfoKey(groupID string) string {
|
||||
return groupInfoKey + groupID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getJoinedSuperGroupsIDKey(userID string) string {
|
||||
return joinedSuperGroupsKey + userID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getJoinedGroupsKey(userID string) string {
|
||||
return joinedGroupsKey + userID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getGroupMembersHashKey(groupID string) string {
|
||||
return groupMembersHashKey + groupID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getGroupMemberIDsKey(groupID string) string {
|
||||
return groupMemberIDsKey + groupID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getGroupMemberInfoKey(groupID, userID string) string {
|
||||
return groupMemberInfoKey + groupID + "-" + userID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getGroupMemberNumKey(groupID string) string {
|
||||
return groupMemberNumKey + groupID
|
||||
}
|
||||
|
||||
/// groupInfo
|
||||
func (g *GroupCache) GetGroupsInfo(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error) {
|
||||
for _, groupID := range groupIDs {
|
||||
group, err := g.GetGroupInfo(ctx, groupID)
|
||||
@@ -58,9 +114,9 @@ func (g *GroupCache) GetGroupInfo(ctx context.Context, groupID string) (group *r
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", *group)
|
||||
}()
|
||||
groupStr, err := g.rcClient.Fetch(g.getGroupInfoCacheKey(groupID), g.expireTime, getGroup)
|
||||
groupStr, err := g.rcClient.Fetch(g.getGroupInfoKey(groupID), g.expireTime, getGroup)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(groupStr), group)
|
||||
return group, utils.Wrap(err, "")
|
||||
@@ -70,7 +126,7 @@ func (g *GroupCache) DelGroupInfo(ctx context.Context, groupID string) (err erro
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
return g.rcClient.TagAsDeleted(g.getGroupInfoCacheKey(groupID))
|
||||
return g.rcClient.TagAsDeleted(g.getGroupInfoKey(groupID))
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelGroupsInfo(ctx context.Context, groupIDs []string) error {
|
||||
@@ -82,21 +138,247 @@ func (g *GroupCache) DelGroupsInfo(ctx context.Context, groupIDs []string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GroupCache) getGroupInfoCacheKey(groupID string) string {
|
||||
return groupInfoCacheKey + groupID
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelJoinedSuperGroupIDs(ctx context.Context, userIDs []string) (err error) {
|
||||
// userJoinSuperGroup
|
||||
func (g *GroupCache) BatchDelJoinedSuperGroupIDs(ctx context.Context, userIDs []string) (err error) {
|
||||
for _, userID := range userIDs {
|
||||
if err := g.rcClient.TagAsDeleted(joinedSuperGroupListCache + userID); err != nil {
|
||||
if err := g.DelJoinedSuperGroupIDs(ctx, userID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelJoinedSuperGroupID(ctx context.Context, userID string) (err error) {
|
||||
func (g *GroupCache) DelJoinedSuperGroupIDs(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
return g.rcClient.TagAsDeleted(joinedSuperGroupListCache + userID)
|
||||
return g.rcClient.TagAsDeleted(g.getJoinedSuperGroupsIDKey(userID))
|
||||
}
|
||||
|
||||
func (g *GroupCache) GetJoinedSuperGroupIDs(ctx context.Context, userID string) (joinedSuperGroupIDs []string, err error) {
|
||||
getJoinedSuperGroupIDList := func() (string, error) {
|
||||
userToSuperGroup, err := g.mongoDB.GetSuperGroupByUserID(ctx, userID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
bytes, err := json.Marshal(userToSuperGroup.GroupIDList)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "joinedSuperGroupIDs", joinedSuperGroupIDs)
|
||||
}()
|
||||
joinedSuperGroupListStr, err := g.rcClient.Fetch(g.getJoinedSuperGroupsIDKey(userID), time.Second*30*60, getJoinedSuperGroupIDList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(joinedSuperGroupListStr), &joinedSuperGroupIDs)
|
||||
return joinedSuperGroupIDs, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
// groupMembersHash
|
||||
func (g *GroupCache) GetGroupMembersHash(ctx context.Context, groupID string) (hashCodeUint64 uint64, err error) {
|
||||
generateHash := func() (string, error) {
|
||||
groupInfo, err := g.GetGroupInfo(ctx, groupID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||
return "0", nil
|
||||
}
|
||||
groupMemberIDList, err := g.GetGroupMemberIDs(ctx, groupID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
sort.Strings(groupMemberIDList)
|
||||
var all string
|
||||
for _, v := range groupMemberIDList {
|
||||
all += v
|
||||
}
|
||||
bi := big.NewInt(0)
|
||||
bi.SetString(utils.Md5(all)[0:8], 16)
|
||||
return strconv.Itoa(int(bi.Uint64())), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "hashCodeUint64", hashCodeUint64)
|
||||
}()
|
||||
hashCodeStr, err := g.rcClient.Fetch(g.getGroupMembersHashKey(groupID), time.Second*30*60, generateHash)
|
||||
if err != nil {
|
||||
return 0, utils.Wrap(err, "fetch failed")
|
||||
}
|
||||
hashCode, err := strconv.Atoi(hashCodeStr)
|
||||
return uint64(hashCode), err
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelGroupMembersHash(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
return g.rcClient.TagAsDeleted(g.getGroupMembersHashKey(groupID))
|
||||
}
|
||||
|
||||
// groupMemberIDs
|
||||
// from redis
|
||||
func (g *GroupCache) GetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error) {
|
||||
f := func() (string, error) {
|
||||
groupInfo, err := g.GetGroupInfo(ctx, groupID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var groupMemberIDList []string
|
||||
if groupInfo.GroupType == constant.SuperGroup {
|
||||
superGroup, err := g.mongoDB.GetSuperGroup(ctx, groupID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
groupMemberIDList = superGroup.MemberIDList
|
||||
} else {
|
||||
groupMemberIDList, err = relation.GetGroupMemberIDListByGroupID(groupID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
bytes, err := json.Marshal(groupMemberIDList)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMemberIDList", groupMemberIDs)
|
||||
}()
|
||||
groupIDListStr, err := g.rcClient.Fetch(g.getGroupMemberIDsKey(groupID), time.Second*30*60, f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(groupIDListStr), &groupMemberIDs)
|
||||
return groupMemberIDs, nil
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelGroupMemberIDs(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
return g.rcClient.TagAsDeleted(g.getGroupMemberIDsKey(groupID))
|
||||
}
|
||||
|
||||
// from local map
|
||||
func (g *GroupCache) LocalGetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error) {
|
||||
remoteHash, err := g.GetGroupMembersHash(ctx, groupID)
|
||||
if err != nil {
|
||||
g.cacheGroupMtx.Lock()
|
||||
defer g.cacheGroupMtx.Unlock()
|
||||
delete(g.cacheGroupMemberUserIDs, groupID)
|
||||
return nil, err
|
||||
}
|
||||
g.cacheGroupMtx.Lock()
|
||||
defer g.cacheGroupMtx.Unlock()
|
||||
if remoteHash == 0 {
|
||||
delete(g.cacheGroupMemberUserIDs, groupID)
|
||||
return []string{}, nil
|
||||
}
|
||||
localCache, ok := g.cacheGroupMemberUserIDs[groupID]
|
||||
if ok && localCache.MemberListHash == remoteHash {
|
||||
return localCache.UserIDs, nil
|
||||
}
|
||||
groupMemberIDsRemote, err := g.GetGroupMemberIDs(ctx, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
g.cacheGroupMemberUserIDs[groupID] = &GroupMemberIDsHash{
|
||||
MemberListHash: remoteHash,
|
||||
UserIDs: groupMemberIDsRemote,
|
||||
}
|
||||
return groupMemberIDsRemote, nil
|
||||
}
|
||||
|
||||
// JoinedGroups
|
||||
func (g *GroupCache) GetJoinedGroupIDs(ctx context.Context, userID string) (joinedGroupIDs []string, err error) {
|
||||
getJoinedGroupIDList := func() (string, error) {
|
||||
joinedGroupList, err := relation.GetJoinedGroupIDListByUserID(userID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
bytes, err := json.Marshal(joinedGroupList)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "joinedGroupIDs", joinedGroupIDs)
|
||||
}()
|
||||
joinedGroupIDListStr, err := g.rcClient.Fetch(g.getJoinedGroupsKey(userID), time.Second*30*60, getJoinedGroupIDList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(joinedGroupIDListStr), &joinedGroupIDs)
|
||||
return joinedGroupIDs, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelJoinedGroupIDs(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
return g.rcClient.TagAsDeleted(g.getJoinedGroupsKey(userID))
|
||||
}
|
||||
|
||||
// GetGroupMemberInfo
|
||||
func (g *GroupCache) GetGroupMemberInfo(ctx context.Context, groupID, userID string) (groupMember *relation.GroupMember, err error) {
|
||||
getGroupMemberInfo := func() (string, error) {
|
||||
groupMemberInfo, err := relation.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
bytes, err := json.Marshal(groupMemberInfo)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupMember", *groupMember)
|
||||
}()
|
||||
groupMemberInfoStr, err := g.rcClient.Fetch(g.getGroupMemberInfoKey(groupID, userID), time.Second*30*60, getGroupMemberInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupMember = &relation.GroupMember{}
|
||||
err = json.Unmarshal([]byte(groupMemberInfoStr), groupMember)
|
||||
return groupMember, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelGroupMemberInfo(ctx context.Context, groupID, userID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID)
|
||||
}()
|
||||
return g.rcClient.TagAsDeleted(g.getGroupMemberInfoKey(groupID, userID))
|
||||
}
|
||||
|
||||
// groupMemberNum
|
||||
func (g *GroupCache) GetGroupMemberNum(ctx context.Context, groupID string) (num int, err error) {
|
||||
getGroupMemberNum := func() (string, error) {
|
||||
num, err := relation.GetGroupMemberNumByGroupID(groupID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strconv.Itoa(int(num)), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "num", num)
|
||||
}()
|
||||
groupMember, err := g.rcClient.Fetch(g.getGroupMemberNumKey(groupID), time.Second*30*60, getGroupMemberNum)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return strconv.Atoi(groupMember)
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelGroupMemberNum(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
return g.rcClient.TagAsDeleted(g.getGroupMemberNumKey(groupID))
|
||||
}
|
||||
|
||||
Vendored
+18
-16
@@ -4,6 +4,7 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mongo"
|
||||
"Open_IM/pkg/common/db/mysql"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -19,31 +20,32 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
userInfoCache = "USER_INFO_CACHE:"
|
||||
//userInfoCache = "USER_INFO_CACHE:"
|
||||
friendRelationCache = "FRIEND_RELATION_CACHE:"
|
||||
blackListCache = "BLACK_LIST_CACHE:"
|
||||
groupCache = "GROUP_CACHE:"
|
||||
//groupCache = "GROUP_CACHE:"
|
||||
//groupInfoCache = "GROUP_INFO_CACHE:"
|
||||
groupOwnerIDCache = "GROUP_OWNER_ID:"
|
||||
joinedGroupListCache = "JOINED_GROUP_LIST_CACHE:"
|
||||
groupMemberInfoCache = "GROUP_MEMBER_INFO_CACHE:"
|
||||
groupAllMemberInfoCache = "GROUP_ALL_MEMBER_INFO_CACHE:"
|
||||
allFriendInfoCache = "ALL_FRIEND_INFO_CACHE:"
|
||||
joinedSuperGroupListCache = "JOINED_SUPER_GROUP_LIST_CACHE:"
|
||||
groupMemberListHashCache = "GROUP_MEMBER_LIST_HASH_CACHE:"
|
||||
groupMemberNumCache = "GROUP_MEMBER_NUM_CACHE:"
|
||||
conversationCache = "CONVERSATION_CACHE:"
|
||||
conversationIDListCache = "CONVERSATION_ID_LIST_CACHE:"
|
||||
extendMsgSetCache = "EXTEND_MSG_SET_CACHE:"
|
||||
extendMsgCache = "EXTEND_MSG_CACHE:"
|
||||
//groupOwnerIDCache = "GROUP_OWNER_ID:"
|
||||
//joinedGroupListCache = "JOINED_GROUP_LIST_CACHE:"
|
||||
//groupMemberInfoCache = "GROUP_MEMBER_INFO_CACHE:"
|
||||
//groupAllMemberInfoCache = "GROUP_ALL_MEMBER_INFO_CACHE:"
|
||||
allFriendInfoCache = "ALL_FRIEND_INFO_CACHE:"
|
||||
//joinedSuperGroupListCache = "JOINED_SUPER_GROUP_LIST_CACHE:"
|
||||
//groupMemberListHashCache = "GROUP_MEMBER_LIST_HASH_CACHE:"
|
||||
//groupMemberNumCache = "GROUP_MEMBER_NUM_CACHE:"
|
||||
conversationCache = "CONVERSATION_CACHE:"
|
||||
conversationIDListCache = "CONVERSATION_ID_LIST_CACHE:"
|
||||
|
||||
extendMsgSetCache = "EXTEND_MSG_SET_CACHE:"
|
||||
extendMsgCache = "EXTEND_MSG_CACHE:"
|
||||
)
|
||||
|
||||
const scanCount = 3000
|
||||
const RandomExpireAdjustment = 0.2
|
||||
|
||||
func (rc *RcClient) DelKeys() {
|
||||
for _, key := range []string{groupCache, friendRelationCache, blackListCache, userInfoCache, groupInfoCacheKey, groupOwnerIDCache, joinedGroupListCache,
|
||||
groupMemberInfoCache, groupAllMemberInfoCache, allFriendInfoCache} {
|
||||
for _, key := range []string{"GROUP_CACHE:", "FRIEND_RELATION_CACHE", "BLACK_LIST_CACHE:", "USER_INFO_CACHE:", "GROUP_INFO_CACHE", groupOwnerIDCache, joinedGroupListCache,
|
||||
groupMemberInfoCache, groupAllMemberInfoCache, "ALL_FRIEND_INFO_CACHE:"} {
|
||||
fName := utils.GetSelfFuncName()
|
||||
var cursor uint64
|
||||
var n int
|
||||
|
||||
Vendored
+90
@@ -0,0 +1,90 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/dtm-labs/rockscache"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
UserExpireTime = time.Second * 60 * 60 * 12
|
||||
userInfoKey = "USER_INFO:"
|
||||
)
|
||||
|
||||
type UserCache struct {
|
||||
userDB *relation.User
|
||||
|
||||
expireTime time.Duration
|
||||
redisClient *RedisClient
|
||||
rcClient *rockscache.Client
|
||||
}
|
||||
|
||||
func NewUserCache(rdb redis.UniversalClient, userDB *relation.User, options rockscache.Options) *UserCache {
|
||||
return &UserCache{
|
||||
userDB: userDB,
|
||||
expireTime: UserExpireTime,
|
||||
redisClient: NewRedisClient(rdb),
|
||||
rcClient: rockscache.NewClient(rdb, options),
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UserCache) getUserInfoKey(userID string) string {
|
||||
return userInfoKey + userID
|
||||
}
|
||||
|
||||
func (u *UserCache) GetUserInfo(ctx context.Context, userID string) (userInfo *relation.User, err error) {
|
||||
getUserInfo := func() (string, error) {
|
||||
userInfo, err := u.userDB.Take(ctx, userID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
bytes, err := json.Marshal(userInfo)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "userInfo", *userInfo)
|
||||
}()
|
||||
userInfoStr, err := u.rcClient.Fetch(u.getUserInfoKey(userID), time.Second*30*60, getUserInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userInfo = &relation.User{}
|
||||
err = json.Unmarshal([]byte(userInfoStr), userInfo)
|
||||
return userInfo, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func (u *UserCache) GetUsersInfo(ctx context.Context, userIDs []string) ([]*relation.User, error) {
|
||||
var users []*relation.User
|
||||
for _, userID := range userIDs {
|
||||
user, err := GetUserInfoFromCache(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
users = append(users, user)
|
||||
}
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func (u *UserCache) DelUserInfo(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
return u.rcClient.TagAsDeleted(u.getUserInfoKey(userID) + userID)
|
||||
}
|
||||
|
||||
func (u *UserCache) DelUsersInfo(ctx context.Context, userIDs []string) (err error) {
|
||||
for _, userID := range userIDs {
|
||||
if err := u.DelUserInfo(ctx, userID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package controller
|
||||
|
||||
import "context"
|
||||
|
||||
type AuthInterface interface {
|
||||
GetTokens(ctx context.Context, userID, platform string) (map[string]int, error)
|
||||
DeleteToken(ctx context.Context, userID, platform string) error
|
||||
CreateToken(ctx context.Context, userID string, platformID int, ttl int64) (string, error)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"context"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -12,9 +13,9 @@ type BlackInterface interface {
|
||||
// Delete 删除黑名单
|
||||
Delete(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blackList []*relation.Black, err error)
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.Black, total int64, err error)
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
CheckIn(ctx context.Context, ownerUserID, blackUserID string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||
}
|
||||
|
||||
type BlackController struct {
|
||||
@@ -27,18 +28,22 @@ func NewBlackController(db *gorm.DB) *BlackController {
|
||||
|
||||
// Create 增加黑名单
|
||||
func (b *BlackController) Create(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.database.Create(ctx, blacks)
|
||||
}
|
||||
|
||||
// Delete 删除黑名单
|
||||
func (b *BlackController) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.database.Delete(ctx, blacks)
|
||||
}
|
||||
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
func (b *BlackController) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blackList []*relation.Black, err error) {
|
||||
func (b *BlackController) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blackList []*relation.Black, total int64, err error) {
|
||||
return b.database.FindOwnerBlacks(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
func (b *BlackController) CheckIn(ctx context.Context, ownerUserID, blackUserID string) (inUser1Blacks bool, inUser2Blacks bool, err error) {
|
||||
func (b *BlackController) CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error) {
|
||||
return b.database.CheckIn(ctx, userID1, userID2)
|
||||
}
|
||||
|
||||
type BlackDatabaseInterface interface {
|
||||
@@ -47,10 +52,9 @@ type BlackDatabaseInterface interface {
|
||||
// Delete 删除黑名单
|
||||
Delete(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blackList []*relation.Black, err error)
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.Black, total int64, err error)
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
CheckIn(ctx context.Context, ownerUserID, blackUserID string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||
}
|
||||
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||
}
|
||||
|
||||
type BlackDatabase struct {
|
||||
@@ -67,16 +71,40 @@ func NewBlackDatabase(db *gorm.DB) *BlackDatabase {
|
||||
|
||||
// Create 增加黑名单
|
||||
func (b *BlackDatabase) Create(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.sqlDB.Create(ctx, blacks)
|
||||
}
|
||||
|
||||
// Delete 删除黑名单
|
||||
func (b *BlackDatabase) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.sqlDB.Delete(ctx, blacks)
|
||||
}
|
||||
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
func (b *BlackDatabase) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blackList []*relation.Black, err error) {
|
||||
func (b *BlackDatabase) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.Black, total int64, err error) {
|
||||
return b.sqlDB.FindOwnerBlacks(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
func (b *BlackDatabase) CheckIn(ctx context.Context, ownerUserID, blackUserID string) (inUser1Blacks bool, inUser2Blacks bool, err error) {
|
||||
func (b *BlackDatabase) CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error) {
|
||||
_, err = b.sqlDB.Take(ctx, userID1, userID2)
|
||||
if err != nil {
|
||||
if errors.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||
return
|
||||
}
|
||||
inUser1Blacks = false
|
||||
} else {
|
||||
inUser1Blacks = true
|
||||
}
|
||||
|
||||
inUser2Blacks = true
|
||||
_, err = b.sqlDB.Take(ctx, userID2, userID1)
|
||||
if err != nil {
|
||||
if errors.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||
return
|
||||
}
|
||||
inUser2Blacks = false
|
||||
} else {
|
||||
inUser2Blacks = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ChatLogInterface interface {
|
||||
CreateChatLog(msg pbMsg.MsgDataToMQ) error
|
||||
GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error)
|
||||
}
|
||||
|
||||
func NewChatLogController(db *gorm.DB) ChatLogInterface {
|
||||
return &ChatLogController{database: NewChatLogDataBase(db)}
|
||||
}
|
||||
|
||||
type ChatLogController struct {
|
||||
database ChatLogDataBaseInterface
|
||||
}
|
||||
|
||||
func (c *ChatLogController) CreateChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||
return c.database.CreateChatLog(msg)
|
||||
}
|
||||
|
||||
func (c *ChatLogController) GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error) {
|
||||
return c.database.GetChatLog(chatLog, pageNumber, showNumber, contentTypeList)
|
||||
}
|
||||
|
||||
type ChatLogDataBaseInterface interface {
|
||||
CreateChatLog(msg pbMsg.MsgDataToMQ) error
|
||||
GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error)
|
||||
}
|
||||
|
||||
type ChatLogDataBase struct {
|
||||
chatLogDB *relation.ChatLog
|
||||
}
|
||||
|
||||
func NewChatLogDataBase(db *gorm.DB) ChatLogDataBaseInterface {
|
||||
return &ChatLogDataBase{chatLogDB: relation.NewChatLog(db)}
|
||||
}
|
||||
|
||||
func (c *ChatLogDataBase) CreateChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||
return c.chatLogDB.Create(msg)
|
||||
}
|
||||
|
||||
func (c *ChatLogDataBase) GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error) {
|
||||
return c.chatLogDB.GetChatLog(chatLog, pageNumber, showNumber, contentTypeList)
|
||||
}
|
||||
@@ -134,8 +134,8 @@ func (g *GroupController) AddUserToSuperGroup(ctx context.Context, groupID strin
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupInterface {
|
||||
groupController := &GroupController{database: newGroupDatabase(db, rdb, mgoDB)}
|
||||
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.Client) GroupInterface {
|
||||
groupController := &GroupController{database: newGroupDatabase(db, rdb, mgoClient)}
|
||||
return groupController
|
||||
}
|
||||
|
||||
@@ -182,23 +182,24 @@ type GroupDataBase struct {
|
||||
mongoDB *unrelation.SuperGroupMgoDB
|
||||
}
|
||||
|
||||
func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupDataBaseInterface {
|
||||
func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.Client) GroupDataBaseInterface {
|
||||
groupDB := relation.NewGroupDB(db)
|
||||
groupMemberDB := relation.NewGroupMemberDB(db)
|
||||
groupRequestDB := relation.NewGroupRequest(db)
|
||||
newDB := db
|
||||
superGroupMgoDB := unrelation.NewSuperGroupMgoDB(mgoClient)
|
||||
database := &GroupDataBase{
|
||||
groupDB: groupDB,
|
||||
groupMemberDB: groupMemberDB,
|
||||
groupRequestDB: groupRequestDB,
|
||||
db: newDB,
|
||||
cache: cache.NewGroupCache(rdb, groupDB, groupMemberDB, groupRequestDB, rockscache.Options{
|
||||
cache: cache.NewGroupCache(rdb, groupDB, groupMemberDB, groupRequestDB, superGroupMgoDB, rockscache.Options{
|
||||
RandomExpireAdjustment: 0.2,
|
||||
DisableCacheRead: false,
|
||||
DisableCacheDelete: false,
|
||||
StrongConsistency: true,
|
||||
}),
|
||||
mongoDB: unrelation.NewSuperGroupMgoDB(mgoDB),
|
||||
mongoDB: superGroupMgoDB,
|
||||
}
|
||||
return database
|
||||
}
|
||||
@@ -272,7 +273,7 @@ func (g *GroupDataBase) CreateSuperGroup(ctx context.Context, groupID string, in
|
||||
return err
|
||||
}
|
||||
|
||||
if err = g.cache.DelJoinedSuperGroupIDs(ctx, initMemberIDList); err != nil {
|
||||
if err = g.cache.BatchDelJoinedSuperGroupIDs(ctx, initMemberIDList); err != nil {
|
||||
_ = sess.AbortTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,14 +7,16 @@ import (
|
||||
)
|
||||
|
||||
type UserInterface interface {
|
||||
//获取指定用户的信息 如果有记录未找到 也返回错误
|
||||
Find(ctx context.Context, userIDs []string) (users []*relation.User, err error)
|
||||
Create(ctx context.Context, users []*relation.User) error
|
||||
Take(ctx context.Context, userID string) (user *relation.User, err error)
|
||||
Update(ctx context.Context, users []*relation.User) (err error)
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||
Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||
//userIDs是否存在 只要有一个存在就为true
|
||||
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
|
||||
}
|
||||
|
||||
type UserController struct {
|
||||
|
||||
@@ -71,44 +71,14 @@ func (b *Black) Take(ctx context.Context, ownerUserID, blockUserID string) (blac
|
||||
return black, utils.Wrap(b.DB.Where("owner_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Take(black).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*Black, err error) {
|
||||
func (b *Black) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*Black, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blackList", blackList)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blacks", blacks)
|
||||
}()
|
||||
return blackList, utils.Wrap(GroupMemberDB.Where("owner_user_id = ?", ownerUserID).Find(&blackList).Error, "")
|
||||
}
|
||||
|
||||
func InsertInToUserBlackList(ctx context.Context, black Black) (err error) {
|
||||
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "black", black)
|
||||
black.CreateTime = time.Now()
|
||||
err = BlackDB.Create(black).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func CheckBlack(ownerUserID, blockUserID string) error {
|
||||
var black Black
|
||||
return BlackDB.Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error
|
||||
}
|
||||
|
||||
func RemoveBlackList(ownerUserID, blockUserID string) error {
|
||||
err := BlackDB.Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(Black{}).Error
|
||||
return utils.Wrap(err, "RemoveBlackList failed")
|
||||
}
|
||||
|
||||
func GetBlackListByUserID(ownerUserID string) ([]Black, error) {
|
||||
var blackListUsersInfo []Black
|
||||
err := BlackDB.Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error
|
||||
err = b.DB.Model(b).Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
return blackListUsersInfo, nil
|
||||
}
|
||||
|
||||
func GetBlackIDListByUserID(ownerUserID string) ([]string, error) {
|
||||
var blackIDList []string
|
||||
err := b.db.Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return blackIDList, nil
|
||||
err = utils.Wrap(b.DB.Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&blacks).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -37,7 +36,11 @@ func (ChatLog) TableName() string {
|
||||
return "chat_logs"
|
||||
}
|
||||
|
||||
func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||
func NewChatLog(db *gorm.DB) *ChatLog {
|
||||
return &ChatLog{DB: db}
|
||||
}
|
||||
|
||||
func (c *ChatLog) Create(msg pbMsg.MsgDataToMQ) error {
|
||||
chatLog := new(ChatLog)
|
||||
copier.Copy(chatLog, msg.MsgData)
|
||||
switch msg.MsgData.SessionType {
|
||||
@@ -61,12 +64,11 @@ func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||
}
|
||||
chatLog.CreateTime = utils.UnixMillSecondToTime(msg.MsgData.CreateTime)
|
||||
chatLog.SendTime = utils.UnixMillSecondToTime(msg.MsgData.SendTime)
|
||||
log.NewDebug("test", "this is ", chatLog)
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Create(chatLog).Error
|
||||
return c.DB.Create(chatLog).Error
|
||||
}
|
||||
|
||||
func GetChatLog(chatLog *ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []ChatLog, error) {
|
||||
mdb := ChatLogDB.Table("chat_logs")
|
||||
func (c *ChatLog) GetChatLog(chatLog *ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []ChatLog, error) {
|
||||
mdb := c.DB.Model(chatLog)
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
mdb = mdb.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
var AppDB *gorm.DB
|
||||
|
||||
type AppVersion struct {
|
||||
Version string `gorm:"column:version;size:64" json:"version"`
|
||||
Type int `gorm:"column:type;primary_key" json:"type"`
|
||||
UpdateTime int `gorm:"column:update_time" json:"update_time"`
|
||||
ForceUpdate bool `gorm:"column:force_update" json:"force_update"`
|
||||
FileName string `gorm:"column:file_name" json:"file_name"`
|
||||
YamlName string `gorm:"column:yaml_name" json:"yaml_name"`
|
||||
UpdateLog string `gorm:"column:update_log" json:"update_log"`
|
||||
}
|
||||
|
||||
func (AppVersion) TableName() string {
|
||||
return "app_version"
|
||||
}
|
||||
|
||||
func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName, updateLog string) error {
|
||||
updateTime := int(time.Now().Unix())
|
||||
app := AppVersion{
|
||||
Version: version,
|
||||
Type: appType,
|
||||
UpdateTime: updateTime,
|
||||
FileName: fileName,
|
||||
YamlName: yamlName,
|
||||
ForceUpdate: forceUpdate,
|
||||
UpdateLog: updateLog,
|
||||
}
|
||||
result := AppDB.Model(AppVersion{}).Where("type = ?", appType).Updates(map[string]interface{}{"force_update": forceUpdate,
|
||||
"version": version, "update_time": int(time.Now().Unix()), "file_name": fileName, "yaml_name": yamlName, "type": appType, "update_log": updateLog})
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
err := AppDB.Create(&app).Error
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetNewestVersion(appType int) (*AppVersion, error) {
|
||||
app := AppVersion{}
|
||||
return &app, AppDB.Model(AppVersion{}).First(&app, appType).Error
|
||||
}
|
||||
@@ -26,7 +26,7 @@ type FriendUser struct {
|
||||
|
||||
func NewFriendDB(db *gorm.DB) *Friend {
|
||||
var friend Friend
|
||||
friend.DB = initModel(db, friend)
|
||||
friend.DB = db
|
||||
return &friend
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ func (u *User) GetByName(ctx context.Context, userName string, showNumber, pageN
|
||||
|
||||
func (u *User) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*User, count int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userName", userName, "showNumber", showNumber, "pageNumber", pageNumber, "users", users)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "content", content, "showNumber", showNumber, "pageNumber", pageNumber, "users", users)
|
||||
}()
|
||||
db := u.DB.Where(" name like ? or user_id = ? ", fmt.Sprintf("%%%s%%", content), content)
|
||||
if err := db.Count(&count).Error; err != nil {
|
||||
|
||||
@@ -108,8 +108,8 @@ func (db *SuperGroupMgoDB) RemoverUserFromSuperGroup(ctx context.Context, groupI
|
||||
|
||||
func (db *SuperGroupMgoDB) GetSuperGroupByUserID(ctx context.Context, userID string) (*UserToSuperGroup, error) {
|
||||
var user UserToSuperGroup
|
||||
_ = db.userToSuperGroupCollection.FindOne(ctx, bson.M{"user_id": userID}).Decode(&user)
|
||||
return &user, nil
|
||||
err := db.userToSuperGroupCollection.FindOne(ctx, bson.M{"user_id": userID}).Decode(&user)
|
||||
return &user, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func (db *SuperGroupMgoDB) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||
|
||||
Reference in New Issue
Block a user