diff --git a/config/redis.yml b/config/redis.yml index 6fe0dd02d..404d18953 100644 --- a/config/redis.yml +++ b/config/redis.yml @@ -1,6 +1,6 @@ -address: [ localhost:16379 ] +address: [ 172.16.8.48:16379 ] username: '' password: openIM123 clusterMode: false db: 0 -maxRetry: 10 \ No newline at end of file +maxRetry: 10 diff --git a/internal/rpc/friend/sync.go b/internal/rpc/friend/sync.go index 9af1c47d3..a73cf6a17 100644 --- a/internal/rpc/friend/sync.go +++ b/internal/rpc/friend/sync.go @@ -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) }, diff --git a/internal/rpc/group/sync.go b/internal/rpc/group/sync.go index 6e0103c83..b35816a7e 100644 --- a/internal/rpc/group/sync.go +++ b/internal/rpc/group/sync.go @@ -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 { diff --git a/internal/rpc/incrversion/option.go b/internal/rpc/incrversion/option.go index 3146985aa..ceb024a3e 100644 --- a/internal/rpc/incrversion/option.go +++ b/internal/rpc/incrversion/option.go @@ -16,6 +16,8 @@ import ( // return maxSync //} +const syncLimit = 200 + const ( tagQuery = iota + 1 tagFull @@ -23,17 +25,17 @@ const ( ) type Option[A, B any] struct { - Ctx context.Context - VersionKey string - VersionID string - VersionNumber uint64 - SyncLimit int + Ctx context.Context + VersionKey string + VersionID string + VersionNumber uint64 + //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) - 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 + //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 } func (o *Option[A, B]) newError(msg string) error { @@ -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() } diff --git a/pkg/common/storage/cache/friend.go b/pkg/common/storage/cache/friend.go index 064e3baae..b451d3675 100644 --- a/pkg/common/storage/cache/friend.go +++ b/pkg/common/storage/cache/friend.go @@ -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) diff --git a/pkg/common/storage/cache/group.go b/pkg/common/storage/cache/group.go index 00a46aaf8..73479bb1b 100644 --- a/pkg/common/storage/cache/group.go +++ b/pkg/common/storage/cache/group.go @@ -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 diff --git a/pkg/common/storage/cache/redis/friend.go b/pkg/common/storage/cache/redis/friend.go index 62fad91cd..01988310c 100644 --- a/pkg/common/storage/cache/redis/friend.go +++ b/pkg/common/storage/cache/redis/friend.go @@ -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) { diff --git a/pkg/common/storage/cache/redis/group.go b/pkg/common/storage/cache/redis/group.go index 9699230ef..4015d5cd9 100644 --- a/pkg/common/storage/cache/redis/group.go +++ b/pkg/common/storage/cache/redis/group.go @@ -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)) diff --git a/pkg/common/storage/controller/friend.go b/pkg/common/storage/controller/friend.go index e03208df9..42c230598 100644 --- a/pkg/common/storage/controller/friend.go +++ b/pkg/common/storage/controller/friend.go @@ -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) diff --git a/pkg/common/storage/controller/group.go b/pkg/common/storage/controller/group.go index f9ee65955..14406420b 100644 --- a/pkg/common/storage/controller/group.go +++ b/pkg/common/storage/controller/group.go @@ -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) diff --git a/pkg/common/storage/model/friend.go b/pkg/common/storage/model/friend.go index c7675e466..60a40d9c2 100644 --- a/pkg/common/storage/model/friend.go +++ b/pkg/common/storage/model/friend.go @@ -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"`