mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-04 19:32:17 +08:00
sync option
This commit is contained in:
parent
693935237a
commit
7e13faaa98
10
pkg/common/storage/cache/redis/group.go
vendored
10
pkg/common/storage/cache/redis/group.go
vendored
@ -257,9 +257,17 @@ func (g *GroupCacheRedis) DelGroupMemberIDs(groupID string) cache.GroupCache {
|
|||||||
return cache
|
return cache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GroupCacheRedis) findUserJoinedGroupID(ctx context.Context, userID string) ([]string, error) {
|
||||||
|
groupIDs, err := g.groupMemberDB.FindUserJoinedGroupID(ctx, userID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return g.groupDB.FindJoinSortGroupID(ctx, groupIDs)
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GroupCacheRedis) GetJoinedGroupIDs(ctx context.Context, userID string) (joinedGroupIDs []string, err error) {
|
func (g *GroupCacheRedis) GetJoinedGroupIDs(ctx context.Context, userID string) (joinedGroupIDs []string, err error) {
|
||||||
return getCache(ctx, g.rcClient, g.getJoinedGroupsKey(userID), g.expireTime, func(ctx context.Context) ([]string, error) {
|
return getCache(ctx, g.rcClient, g.getJoinedGroupsKey(userID), g.expireTime, func(ctx context.Context) ([]string, error) {
|
||||||
return g.groupMemberDB.FindUserJoinedGroupID(ctx, userID)
|
return g.findUserJoinedGroupID(ctx, userID)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -116,6 +116,8 @@ type GroupDatabase interface {
|
|||||||
|
|
||||||
FindMaxGroupMemberVersionCache(ctx context.Context, groupID string) (*model.VersionLog, error)
|
FindMaxGroupMemberVersionCache(ctx context.Context, groupID string) (*model.VersionLog, error)
|
||||||
FindMaxJoinGroupVersionCache(ctx context.Context, userID string) (*model.VersionLog, error)
|
FindMaxJoinGroupVersionCache(ctx context.Context, userID string) (*model.VersionLog, error)
|
||||||
|
|
||||||
|
SearchJoinGroup(ctx context.Context, userID string, keyword string, pagination pagination.Pagination) (int64, []*model.Group, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGroupDatabase(
|
func NewGroupDatabase(
|
||||||
@ -510,3 +512,11 @@ func (g *groupDatabase) FindMaxGroupMemberVersionCache(ctx context.Context, grou
|
|||||||
func (g *groupDatabase) FindMaxJoinGroupVersionCache(ctx context.Context, userID string) (*model.VersionLog, error) {
|
func (g *groupDatabase) FindMaxJoinGroupVersionCache(ctx context.Context, userID string) (*model.VersionLog, error) {
|
||||||
return g.cache.FindMaxJoinGroupVersion(ctx, userID)
|
return g.cache.FindMaxJoinGroupVersion(ctx, userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *groupDatabase) SearchJoinGroup(ctx context.Context, userID string, keyword string, pagination pagination.Pagination) (int64, []*model.Group, error) {
|
||||||
|
groupIDs, err := g.cache.GetJoinedGroupIDs(ctx, userID)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, err
|
||||||
|
}
|
||||||
|
return g.groupDB.SearchJoin(ctx, groupIDs, keyword, pagination)
|
||||||
|
}
|
||||||
|
|||||||
@ -32,4 +32,8 @@ type Group interface {
|
|||||||
CountTotal(ctx context.Context, before *time.Time) (count int64, err error)
|
CountTotal(ctx context.Context, before *time.Time) (count int64, err error)
|
||||||
// Get Group total quantity every day
|
// Get Group total quantity every day
|
||||||
CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error)
|
CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error)
|
||||||
|
|
||||||
|
FindJoinSortGroupID(ctx context.Context, groupIDs []string) ([]string, error)
|
||||||
|
|
||||||
|
SearchJoin(ctx context.Context, groupIDs []string, keyword string, pagination pagination.Pagination) (int64, []*model.Group, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,10 @@ func NewFriendMongo(db *mongo.Database) (database.Friend, error) {
|
|||||||
return &FriendMgo{coll: coll, owner: owner}, nil
|
return &FriendMgo{coll: coll, owner: owner}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FriendMgo) friendSort() any {
|
||||||
|
return bson.D{{"is_pinned", -1}, {"friend_nickname", 1}, {"create_time", 1}}
|
||||||
|
}
|
||||||
|
|
||||||
// Create inserts multiple friend records.
|
// Create inserts multiple friend records.
|
||||||
func (f *FriendMgo) Create(ctx context.Context, friends []*model.Friend) error {
|
func (f *FriendMgo) Create(ctx context.Context, friends []*model.Friend) error {
|
||||||
return mongoutil.IncrVersion(func() error {
|
return mongoutil.IncrVersion(func() error {
|
||||||
@ -145,13 +149,13 @@ func (f *FriendMgo) FindReversalFriends(ctx context.Context, friendUserID string
|
|||||||
// FindOwnerFriends retrieves a paginated list of friends for a given owner.
|
// FindOwnerFriends retrieves a paginated list of friends for a given owner.
|
||||||
func (f *FriendMgo) FindOwnerFriends(ctx context.Context, ownerUserID string, pagination pagination.Pagination) (int64, []*model.Friend, error) {
|
func (f *FriendMgo) FindOwnerFriends(ctx context.Context, ownerUserID string, pagination pagination.Pagination) (int64, []*model.Friend, error) {
|
||||||
filter := bson.M{"owner_user_id": ownerUserID}
|
filter := bson.M{"owner_user_id": ownerUserID}
|
||||||
opt := options.Find().SetSort(bson.D{{"friend_nickname", 1}, {"create_time", 1}})
|
opt := options.Find().SetSort(f.friendSort())
|
||||||
return mongoutil.FindPage[*model.Friend](ctx, f.coll, filter, pagination, opt)
|
return mongoutil.FindPage[*model.Friend](ctx, f.coll, filter, pagination, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendMgo) FindOwnerFriendUserIds(ctx context.Context, ownerUserID string, limit int) ([]string, error) {
|
func (f *FriendMgo) FindOwnerFriendUserIds(ctx context.Context, ownerUserID string, limit int) ([]string, error) {
|
||||||
filter := bson.M{"owner_user_id": ownerUserID}
|
filter := bson.M{"owner_user_id": ownerUserID}
|
||||||
opt := options.Find().SetProjection(bson.M{"_id": 0, "friend_user_id": 1}).SetSort(bson.D{{"friend_nickname", 1}, {"create_time", 1}}).SetLimit(int64(limit))
|
opt := options.Find().SetProjection(bson.M{"_id": 0, "friend_user_id": 1}).SetSort(f.friendSort()).SetLimit(int64(limit))
|
||||||
return mongoutil.Find[string](ctx, f.coll, filter, opt)
|
return mongoutil.Find[string](ctx, f.coll, filter, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +201,7 @@ func (f *FriendMgo) FindFriendUserID(ctx context.Context, friendUserID string) (
|
|||||||
filter := bson.M{
|
filter := bson.M{
|
||||||
"friend_user_id": friendUserID,
|
"friend_user_id": friendUserID,
|
||||||
}
|
}
|
||||||
return mongoutil.Find[string](ctx, f.coll, filter, options.Find().SetProjection(bson.M{"_id": 0, "owner_user_id": 1}))
|
return mongoutil.Find[string](ctx, f.coll, filter, options.Find().SetProjection(bson.M{"_id": 0, "owner_user_id": 1}).SetSort(f.friendSort()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendMgo) UpdateFriendUserInfo(ctx context.Context, friendUserID string, nickname string, faceURL string) error {
|
func (f *FriendMgo) UpdateFriendUserInfo(ctx context.Context, friendUserID string, nickname string, faceURL string) error {
|
||||||
@ -209,14 +213,16 @@ func (f *FriendMgo) UpdateFriendUserInfo(ctx context.Context, friendUserID strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendMgo) SearchFriend(ctx context.Context, ownerUserID, keyword string, pagination pagination.Pagination) (int64, []*model.Friend, error) {
|
func (f *FriendMgo) SearchFriend(ctx context.Context, ownerUserID, keyword string, pagination pagination.Pagination) (int64, []*model.Friend, error) {
|
||||||
//where := bson.M{
|
filter := bson.M{
|
||||||
// "owner_user_id": ownerUserID,
|
"owner_user_id": ownerUserID,
|
||||||
// "$or": []bson.M{
|
}
|
||||||
// {"remark": bson.M{"$regex": keyword, "$options": "i"}},
|
if keyword != "" {
|
||||||
// {"friend_user_id": bson.M{"$regex": keyword, "$options": "i"}},
|
filter["$or"] = []bson.M{
|
||||||
// {"nickname": bson.M{"$regex": keyword, "$options": "i"}},
|
{"remark": bson.M{"$regex": keyword, "$options": "i"}},
|
||||||
// },
|
{"nickname": bson.M{"$regex": keyword, "$options": "i"}},
|
||||||
//}
|
{"friend_user_id": bson.M{"$regex": keyword, "$options": "i"}},
|
||||||
//return f.aggregatePagination(ctx, where, pagination)
|
}
|
||||||
panic("todo")
|
}
|
||||||
|
opt := options.Find().SetSort(f.friendSort())
|
||||||
|
return mongoutil.FindPage[*model.Friend](ctx, f.coll, filter, pagination, opt)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,10 @@ type GroupMgo struct {
|
|||||||
coll *mongo.Collection
|
coll *mongo.Collection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GroupMgo) sortGroup() any {
|
||||||
|
return bson.D{{"group_name", 1}, {"create_time", 1}}
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GroupMgo) Create(ctx context.Context, groups []*model.Group) (err error) {
|
func (g *GroupMgo) Create(ctx context.Context, groups []*model.Group) (err error) {
|
||||||
return mongoutil.InsertMany(ctx, g.coll, groups)
|
return mongoutil.InsertMany(ctx, g.coll, groups)
|
||||||
}
|
}
|
||||||
@ -126,3 +130,32 @@ func (g *GroupMgo) CountRangeEverydayTotal(ctx context.Context, start time.Time,
|
|||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GroupMgo) FindJoinSortGroupID(ctx context.Context, groupIDs []string) ([]string, error) {
|
||||||
|
if len(groupIDs) < 2 {
|
||||||
|
return groupIDs, nil
|
||||||
|
}
|
||||||
|
filter := bson.M{
|
||||||
|
"group_id": bson.M{"$in": groupIDs},
|
||||||
|
"status": bson.M{"$ne": constant.GroupStatusDismissed},
|
||||||
|
}
|
||||||
|
opt := options.Find().SetSort(g.sortGroup()).SetProjection(bson.M{"_id": 0, "group_id": 1})
|
||||||
|
return mongoutil.Find[string](ctx, g.coll, filter, opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GroupMgo) SearchJoin(ctx context.Context, groupIDs []string, keyword string, pagination pagination.Pagination) (int64, []*model.Group, error) {
|
||||||
|
if len(groupIDs) == 0 {
|
||||||
|
return 0, nil, nil
|
||||||
|
}
|
||||||
|
filter := bson.M{
|
||||||
|
"group_id": bson.M{"$in": groupIDs},
|
||||||
|
"status": bson.M{"$ne": constant.GroupStatusDismissed},
|
||||||
|
}
|
||||||
|
if keyword != "" {
|
||||||
|
filter["group_name"] = bson.M{"$regex": keyword}
|
||||||
|
}
|
||||||
|
// Define the sorting options
|
||||||
|
opts := options.Find().SetSort(g.sortGroup())
|
||||||
|
// Perform the search with pagination and sorting
|
||||||
|
return mongoutil.FindPage[*model.Group](ctx, g.coll, filter, pagination, opts)
|
||||||
|
}
|
||||||
|
|||||||
@ -57,7 +57,7 @@ type GroupMemberMgo struct {
|
|||||||
join database.VersionLog
|
join database.VersionLog
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupMemberMgo) sortBson() any {
|
func (g *GroupMemberMgo) memberSort() any {
|
||||||
return bson.D{{"role_level", -1}, {"create_time", -1}}
|
return bson.D{{"role_level", -1}, {"create_time", -1}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ func (g *GroupMemberMgo) Update(ctx context.Context, groupID string, userID stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupMemberMgo) FindMemberUserID(ctx context.Context, groupID string) (userIDs []string, err error) {
|
func (g *GroupMemberMgo) FindMemberUserID(ctx context.Context, groupID string) (userIDs []string, err error) {
|
||||||
return mongoutil.Find[string](ctx, g.coll, bson.M{"group_id": groupID}, options.Find().SetProjection(bson.M{"_id": 0, "user_id": 1}).SetSort(g.sortBson()))
|
return mongoutil.Find[string](ctx, g.coll, bson.M{"group_id": groupID}, options.Find().SetProjection(bson.M{"_id": 0, "user_id": 1}).SetSort(g.memberSort()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupMemberMgo) Take(ctx context.Context, groupID string, userID string) (groupMember *model.GroupMember, err error) {
|
func (g *GroupMemberMgo) Take(ctx context.Context, groupID string, userID string) (groupMember *model.GroupMember, err error) {
|
||||||
@ -143,13 +143,13 @@ func (g *GroupMemberMgo) FindRoleLevelUserIDs(ctx context.Context, groupID strin
|
|||||||
return mongoutil.Find[string](ctx, g.coll, bson.M{"group_id": groupID, "role_level": roleLevel}, options.Find().SetProjection(bson.M{"_id": 0, "user_id": 1}))
|
return mongoutil.Find[string](ctx, g.coll, bson.M{"group_id": groupID, "role_level": roleLevel}, options.Find().SetProjection(bson.M{"_id": 0, "user_id": 1}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupMemberMgo) SearchMember(ctx context.Context, keyword string, groupID string, pagination pagination.Pagination) (total int64, groupList []*model.GroupMember, err error) {
|
func (g *GroupMemberMgo) SearchMember(ctx context.Context, keyword string, groupID string, pagination pagination.Pagination) (int64, []*model.GroupMember, error) {
|
||||||
filter := bson.M{"group_id": groupID, "nickname": bson.M{"$regex": keyword}}
|
filter := bson.M{"group_id": groupID, "nickname": bson.M{"$regex": keyword}}
|
||||||
return mongoutil.FindPage[*model.GroupMember](ctx, g.coll, filter, pagination, options.Find().SetSort(g.sortBson()))
|
return mongoutil.FindPage[*model.GroupMember](ctx, g.coll, filter, pagination, options.Find().SetSort(g.memberSort()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupMemberMgo) FindUserJoinedGroupID(ctx context.Context, userID string) (groupIDs []string, err error) {
|
func (g *GroupMemberMgo) FindUserJoinedGroupID(ctx context.Context, userID string) (groupIDs []string, err error) {
|
||||||
return mongoutil.Find[string](ctx, g.coll, bson.M{"user_id": userID}, options.Find().SetProjection(bson.M{"_id": 0, "group_id": 1}).SetSort(g.sortBson()))
|
return mongoutil.Find[string](ctx, g.coll, bson.M{"user_id": userID}, options.Find().SetProjection(bson.M{"_id": 0, "group_id": 1}).SetSort(g.memberSort()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupMemberMgo) TakeGroupMemberNum(ctx context.Context, groupID string) (count int64, err error) {
|
func (g *GroupMemberMgo) TakeGroupMemberNum(ctx context.Context, groupID string) (count int64, err error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user