mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 21:02:11 +08:00
sync option
This commit is contained in:
parent
c5f565ff20
commit
a1523f47e7
@ -1,4 +1,4 @@
|
||||
address: [ localhost:16379 ]
|
||||
address: [ 172.16.8.48:16379 ]
|
||||
username: ''
|
||||
password: openIM123
|
||||
clusterMode: false
|
||||
|
||||
@ -10,30 +10,6 @@ import (
|
||||
"github.com/openimsdk/protocol/relation"
|
||||
)
|
||||
|
||||
//func (s *friendServer) SearchFriends(ctx context.Context, req *pbfriend.SearchFriendsReq) (*pbfriend.SearchFriendsResp, error) {
|
||||
// if err := s.userRpcClient.Access(ctx, req.UserID); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if req.Keyword == "" {
|
||||
// total, friends, err := s.friendDatabase.PageOwnerFriends(ctx, req.UserID, req.Pagination)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return &pbfriend.SearchFriendsResp{
|
||||
// Total: total,
|
||||
// Friends: friendsDB2PB(friends),
|
||||
// }, nil
|
||||
// }
|
||||
// total, friends, err := s.friendDatabase.SearchFriend(ctx, req.UserID, req.Keyword, req.Pagination)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return &pbfriend.SearchFriendsResp{
|
||||
// Total: total,
|
||||
// Friends: friendsDB2PB(friends),
|
||||
// }, nil
|
||||
//}
|
||||
|
||||
func (s *friendServer) GetIncrementalFriends(ctx context.Context, req *relation.GetIncrementalFriendsReq) (*relation.GetIncrementalFriendsResp, error) {
|
||||
if err := authverify.CheckAccessV3(ctx, req.UserID, s.config.Share.IMAdminUserID); err != nil {
|
||||
return nil, err
|
||||
@ -43,10 +19,8 @@ func (s *friendServer) GetIncrementalFriends(ctx context.Context, req *relation.
|
||||
VersionKey: req.UserID,
|
||||
VersionID: req.VersionID,
|
||||
VersionNumber: req.Version,
|
||||
SyncLimit: s.config.RpcConfig.FriendSyncCount,
|
||||
Version: s.friendDatabase.FindFriendIncrVersion,
|
||||
CacheMaxVersion: s.friendDatabase.FindMaxFriendVersionCache,
|
||||
SortID: s.friendDatabase.FindSortFriendUserIDs,
|
||||
Find: func(ctx context.Context, ids []string) ([]*sdkws.FriendInfo, error) {
|
||||
return s.getFriend(ctx, req.UserID, ids)
|
||||
},
|
||||
|
||||
@ -15,10 +15,8 @@ func (s *groupServer) GetIncrementalGroupMember(ctx context.Context, req *pbgrou
|
||||
VersionKey: req.GroupID,
|
||||
VersionID: req.VersionID,
|
||||
VersionNumber: req.Version,
|
||||
SyncLimit: s.config.RpcConfig.GroupSyncCount,
|
||||
Version: s.db.FindMemberIncrVersion,
|
||||
CacheMaxVersion: s.db.FindMaxGroupMemberVersionCache,
|
||||
SortID: s.db.FindSortGroupMemberUserIDs,
|
||||
Find: func(ctx context.Context, ids []string) ([]*sdkws.GroupMemberFullInfo, error) {
|
||||
return s.getGroupMembersInfo(ctx, req.GroupID, ids)
|
||||
},
|
||||
@ -46,10 +44,8 @@ func (s *groupServer) GetIncrementalJoinGroup(ctx context.Context, req *pbgroup.
|
||||
VersionKey: req.UserID,
|
||||
VersionID: req.VersionID,
|
||||
VersionNumber: req.Version,
|
||||
SyncLimit: s.config.RpcConfig.GroupSyncCount,
|
||||
Version: s.db.FindJoinIncrVersion,
|
||||
CacheMaxVersion: s.db.FindMaxJoinGroupVersionCache,
|
||||
SortID: s.db.FindSortJoinGroupIDs,
|
||||
Find: s.getGroupsInfo,
|
||||
ID: func(elem *sdkws.GroupInfo) string { return elem.GroupID },
|
||||
Resp: func(version *model.VersionLog, delIDs []string, list []*sdkws.GroupInfo, full bool) *pbgroup.GetIncrementalJoinGroupResp {
|
||||
|
||||
@ -16,6 +16,8 @@ import (
|
||||
// return maxSync
|
||||
//}
|
||||
|
||||
const syncLimit = 200
|
||||
|
||||
const (
|
||||
tagQuery = iota + 1
|
||||
tagFull
|
||||
@ -27,10 +29,10 @@ type Option[A, B any] struct {
|
||||
VersionKey string
|
||||
VersionID string
|
||||
VersionNumber uint64
|
||||
SyncLimit int
|
||||
//SyncLimit int
|
||||
CacheMaxVersion func(ctx context.Context, dId string) (*model.VersionLog, error)
|
||||
Version func(ctx context.Context, dId string, version uint, limit int) (*model.VersionLog, error)
|
||||
SortID func(ctx context.Context, dId string) ([]string, error)
|
||||
//SortID func(ctx context.Context, dId string) ([]string, error)
|
||||
Find func(ctx context.Context, ids []string) ([]A, error)
|
||||
ID func(elem A) string
|
||||
Resp func(version *model.VersionLog, delIDs []string, list []A, full bool) *B
|
||||
@ -47,15 +49,15 @@ func (o *Option[A, B]) check() error {
|
||||
if o.VersionKey == "" {
|
||||
return o.newError("versionKey is empty")
|
||||
}
|
||||
if o.SyncLimit <= 0 {
|
||||
return o.newError("invalid synchronization quantity")
|
||||
}
|
||||
//if o.SyncLimit <= 0 {
|
||||
// return o.newError("invalid synchronization quantity")
|
||||
//}
|
||||
if o.Version == nil {
|
||||
return o.newError("func version is nil")
|
||||
}
|
||||
if o.SortID == nil {
|
||||
return o.newError("func allID is nil")
|
||||
}
|
||||
//if o.SortID == nil {
|
||||
// return o.newError("func allID is nil")
|
||||
//}
|
||||
if o.Find == nil {
|
||||
return o.newError("func find is nil")
|
||||
}
|
||||
@ -81,7 +83,7 @@ func (o *Option[A, B]) getVersion(tag *int) (*model.VersionLog, error) {
|
||||
if o.CacheMaxVersion == nil {
|
||||
if o.validVersion() {
|
||||
*tag = tagQuery
|
||||
return o.Version(o.Ctx, o.VersionKey, uint(o.VersionNumber), o.SyncLimit)
|
||||
return o.Version(o.Ctx, o.VersionKey, uint(o.VersionNumber), syncLimit)
|
||||
}
|
||||
*tag = tagFull
|
||||
return o.Version(o.Ctx, o.VersionKey, 0, 0)
|
||||
@ -103,7 +105,7 @@ func (o *Option[A, B]) getVersion(tag *int) (*model.VersionLog, error) {
|
||||
return cache, nil
|
||||
}
|
||||
*tag = tagQuery
|
||||
return o.Version(o.Ctx, o.VersionKey, uint(o.VersionNumber), o.SyncLimit)
|
||||
return o.Version(o.Ctx, o.VersionKey, uint(o.VersionNumber), syncLimit)
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,12 +133,11 @@ func (o *Option[A, B]) Build() (*B, error) {
|
||||
deleteIDs []string
|
||||
changeIDs []string
|
||||
)
|
||||
//full := o.VersionID != version.ID.Hex() || version.Full()
|
||||
if full {
|
||||
changeIDs, err = o.SortID(o.Ctx, o.VersionKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//changeIDs, err = o.SortID(o.Ctx, o.VersionKey)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
} else {
|
||||
deleteIDs, changeIDs = version.DeleteAndChangeIDs()
|
||||
}
|
||||
|
||||
2
pkg/common/storage/cache/friend.go
vendored
2
pkg/common/storage/cache/friend.go
vendored
@ -39,7 +39,7 @@ type FriendCache interface {
|
||||
|
||||
//DelSortFriendUserIDs(ownerUserIDs ...string) FriendCache
|
||||
|
||||
FindSortFriendUserIDs(ctx context.Context, ownerUserID string) ([]string, error)
|
||||
//FindSortFriendUserIDs(ctx context.Context, ownerUserID string) ([]string, error)
|
||||
|
||||
//FindFriendIncrVersion(ctx context.Context, ownerUserID string, version uint, limit int) (*relationtb.VersionLog, error)
|
||||
|
||||
|
||||
4
pkg/common/storage/cache/group.go
vendored
4
pkg/common/storage/cache/group.go
vendored
@ -59,8 +59,8 @@ type GroupCache interface {
|
||||
GetGroupMemberNum(ctx context.Context, groupID string) (memberNum int64, err error)
|
||||
DelGroupsMemberNum(groupID ...string) GroupCache
|
||||
|
||||
FindSortGroupMemberUserIDs(ctx context.Context, groupID string) ([]string, error)
|
||||
FindSortJoinGroupIDs(ctx context.Context, userID string) ([]string, error)
|
||||
//FindSortGroupMemberUserIDs(ctx context.Context, groupID string) ([]string, error)
|
||||
//FindSortJoinGroupIDs(ctx context.Context, userID string) ([]string, error)
|
||||
|
||||
DelMaxGroupMemberVersion(groupIDs ...string) GroupCache
|
||||
DelMaxJoinGroupVersion(userIDs ...string) GroupCache
|
||||
|
||||
20
pkg/common/storage/cache/redis/friend.go
vendored
20
pkg/common/storage/cache/redis/friend.go
vendored
@ -193,16 +193,16 @@ func (f *FriendCacheRedis) DelMaxFriendVersion(ownerUserIDs ...string) cache.Fri
|
||||
return newFriendCache
|
||||
}
|
||||
|
||||
func (f *FriendCacheRedis) FindSortFriendUserIDs(ctx context.Context, ownerUserID string) ([]string, error) {
|
||||
userIDs, err := f.GetFriendIDs(ctx, ownerUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(userIDs) > f.syncCount {
|
||||
userIDs = userIDs[:f.syncCount]
|
||||
}
|
||||
return userIDs, nil
|
||||
}
|
||||
//func (f *FriendCacheRedis) FindSortFriendUserIDs(ctx context.Context, ownerUserID string) ([]string, error) {
|
||||
// userIDs, err := f.GetFriendIDs(ctx, ownerUserID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if len(userIDs) > f.syncCount {
|
||||
// userIDs = userIDs[:f.syncCount]
|
||||
// }
|
||||
// return userIDs, nil
|
||||
//}
|
||||
|
||||
func (f *FriendCacheRedis) FindMaxFriendVersion(ctx context.Context, ownerUserID string) (*model.VersionLog, error) {
|
||||
return getCache(ctx, f.rcClient, f.getFriendMaxVersionKey(ownerUserID), f.expireTime, func(ctx context.Context) (*model.VersionLog, error) {
|
||||
|
||||
42
pkg/common/storage/cache/redis/group.go
vendored
42
pkg/common/storage/cache/redis/group.go
vendored
@ -405,27 +405,27 @@ func (g *GroupCacheRedis) FindGroupMemberUser(ctx context.Context, groupIDs []st
|
||||
})
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) FindSortGroupMemberUserIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
userIDs, err := g.GetGroupMemberIDs(ctx, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(userIDs) > g.syncCount {
|
||||
userIDs = userIDs[:g.syncCount]
|
||||
}
|
||||
return userIDs, nil
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) FindSortJoinGroupIDs(ctx context.Context, userID string) ([]string, error) {
|
||||
groupIDs, err := g.GetJoinedGroupIDs(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(groupIDs) > g.syncCount {
|
||||
groupIDs = groupIDs[:g.syncCount]
|
||||
}
|
||||
return groupIDs, nil
|
||||
}
|
||||
//func (g *GroupCacheRedis) FindSortGroupMemberUserIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
// userIDs, err := g.GetGroupMemberIDs(ctx, groupID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if len(userIDs) > g.syncCount {
|
||||
// userIDs = userIDs[:g.syncCount]
|
||||
// }
|
||||
// return userIDs, nil
|
||||
//}
|
||||
//
|
||||
//func (g *GroupCacheRedis) FindSortJoinGroupIDs(ctx context.Context, userID string) ([]string, error) {
|
||||
// groupIDs, err := g.GetJoinedGroupIDs(ctx, userID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if len(groupIDs) > g.syncCount {
|
||||
// groupIDs = groupIDs[:g.syncCount]
|
||||
// }
|
||||
// return groupIDs, nil
|
||||
//}
|
||||
|
||||
func (g *GroupCacheRedis) DelMaxGroupMemberVersion(groupIDs ...string) cache.GroupCache {
|
||||
keys := make([]string, 0, len(groupIDs))
|
||||
|
||||
@ -78,7 +78,7 @@ type FriendDatabase interface {
|
||||
// UpdateFriends updates fields for friends
|
||||
UpdateFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, val map[string]any) (err error)
|
||||
|
||||
FindSortFriendUserIDs(ctx context.Context, ownerUserID string) ([]string, error)
|
||||
//FindSortFriendUserIDs(ctx context.Context, ownerUserID string) ([]string, error)
|
||||
|
||||
FindFriendIncrVersion(ctx context.Context, ownerUserID string, version uint, limit int) (*model.VersionLog, error)
|
||||
|
||||
@ -360,9 +360,9 @@ func (f *friendDatabase) UpdateFriends(ctx context.Context, ownerUserID string,
|
||||
})
|
||||
}
|
||||
|
||||
func (f *friendDatabase) FindSortFriendUserIDs(ctx context.Context, ownerUserID string) ([]string, error) {
|
||||
return f.cache.FindSortFriendUserIDs(ctx, ownerUserID)
|
||||
}
|
||||
//func (f *friendDatabase) FindSortFriendUserIDs(ctx context.Context, ownerUserID string) ([]string, error) {
|
||||
// return f.cache.FindSortFriendUserIDs(ctx, ownerUserID)
|
||||
//}
|
||||
|
||||
func (f *friendDatabase) FindFriendIncrVersion(ctx context.Context, ownerUserID string, version uint, limit int) (*model.VersionLog, error) {
|
||||
return f.friend.FindIncrVersion(ctx, ownerUserID, version, limit)
|
||||
|
||||
@ -110,9 +110,8 @@ type GroupDatabase interface {
|
||||
FindMemberIncrVersion(ctx context.Context, groupID string, version uint, limit int) (*model.VersionLog, error)
|
||||
FindJoinIncrVersion(ctx context.Context, userID string, version uint, limit int) (*model.VersionLog, error)
|
||||
|
||||
FindSortGroupMemberUserIDs(ctx context.Context, groupID string) ([]string, error)
|
||||
|
||||
FindSortJoinGroupIDs(ctx context.Context, userID string) ([]string, error)
|
||||
//FindSortGroupMemberUserIDs(ctx context.Context, groupID string) ([]string, error)
|
||||
//FindSortJoinGroupIDs(ctx context.Context, userID string) ([]string, error)
|
||||
|
||||
FindMaxGroupMemberVersionCache(ctx context.Context, groupID string) (*model.VersionLog, error)
|
||||
FindMaxJoinGroupVersionCache(ctx context.Context, userID string) (*model.VersionLog, error)
|
||||
@ -497,13 +496,13 @@ func (g *groupDatabase) FindJoinIncrVersion(ctx context.Context, userID string,
|
||||
return g.groupMemberDB.FindJoinIncrVersion(ctx, userID, version, limit)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) FindSortGroupMemberUserIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
return g.cache.FindSortGroupMemberUserIDs(ctx, groupID)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) FindSortJoinGroupIDs(ctx context.Context, userID string) ([]string, error) {
|
||||
return g.cache.FindSortJoinGroupIDs(ctx, userID)
|
||||
}
|
||||
//func (g *groupDatabase) FindSortGroupMemberUserIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
// return g.cache.FindSortGroupMemberUserIDs(ctx, groupID)
|
||||
//}
|
||||
//
|
||||
//func (g *groupDatabase) FindSortJoinGroupIDs(ctx context.Context, userID string) ([]string, error) {
|
||||
// return g.cache.FindSortJoinGroupIDs(ctx, userID)
|
||||
//}
|
||||
|
||||
func (g *groupDatabase) FindMaxGroupMemberVersionCache(ctx context.Context, groupID string) (*model.VersionLog, error) {
|
||||
return g.cache.FindMaxGroupMemberVersion(ctx, groupID)
|
||||
|
||||
@ -22,8 +22,6 @@ import (
|
||||
type Friend struct {
|
||||
OwnerUserID string `bson:"owner_user_id"`
|
||||
FriendUserID string `bson:"friend_user_id"`
|
||||
FriendNickname string `bson:"friend_nickname"`
|
||||
FriendFaceURL string `bson:"friend_face_url"`
|
||||
Remark string `bson:"remark"`
|
||||
CreateTime time.Time `bson:"create_time"`
|
||||
AddSource int32 `bson:"add_source"`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user