fix: group info get is empty when user not in this group.
This commit is contained in:
parent
2fd7076c8c
commit
0e64d54534
@ -209,7 +209,7 @@ func (g *Group) GetSpecifiedGroupsInfo(ctx context.Context, groupIDs []string) (
|
|||||||
return datautil.Batch(ServerGroupToLocalGroup, serverGroupInfo), nil
|
return datautil.Batch(ServerGroupToLocalGroup, serverGroupInfo), nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return dataFetcher.FetchMissingAndFillLocal(ctx, groupIDs)
|
return dataFetcher.FetchMissingAndCombineLocal(ctx, groupIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) SearchGroups(ctx context.Context, param sdk_params_callback.SearchGroupsParam) ([]*model_struct.LocalGroup, error) {
|
func (g *Group) SearchGroups(ctx context.Context, param sdk_params_callback.SearchGroupsParam) ([]*model_struct.LocalGroup, error) {
|
||||||
@ -247,6 +247,25 @@ func (g *Group) GetGroupMemberListByJoinTimeFilter(ctx context.Context, groupID
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) GetSpecifiedGroupMembersInfo(ctx context.Context, groupID string, userIDList []string) ([]*model_struct.LocalGroupMember, error) {
|
func (g *Group) GetSpecifiedGroupMembersInfo(ctx context.Context, groupID string, userIDList []string) ([]*model_struct.LocalGroupMember, error) {
|
||||||
|
lvs, err := g.db.GetVersionSync(ctx, g.groupTableName(), g.loginUserID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if datautil.Contain(groupID, lvs.UIDList...) {
|
||||||
|
|
||||||
|
_, err := g.db.GetVersionSync(ctx, g.groupAndMemberVersionTableName(), groupID)
|
||||||
|
if err != nil {
|
||||||
|
if errs.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err := g.IncrSyncGroupAndMember(ctx, groupID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { // If the user is no longer in the group, return nil immediately
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
dataFetcher := datafetcher.NewDataFetcher(
|
dataFetcher := datafetcher.NewDataFetcher(
|
||||||
g.db,
|
g.db,
|
||||||
g.groupAndMemberVersionTableName(),
|
g.groupAndMemberVersionTableName(),
|
||||||
@ -276,13 +295,26 @@ func (g *Group) GetSpecifiedGroupMembersInfo(ctx context.Context, groupID string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) GetGroupMemberList(ctx context.Context, groupID string, filter, offset, count int32) ([]*model_struct.LocalGroupMember, error) {
|
func (g *Group) GetGroupMemberList(ctx context.Context, groupID string, filter, offset, count int32) ([]*model_struct.LocalGroupMember, error) {
|
||||||
_, err := g.db.GetVersionSync(ctx, g.groupAndMemberVersionTableName(), groupID)
|
lvs, err := g.db.GetVersionSync(ctx, g.groupTableName(), g.loginUserID)
|
||||||
if errs.Unwrap(err) == gorm.ErrRecordNotFound {
|
if err != nil {
|
||||||
err := g.IncrSyncGroupAndMember(ctx, groupID)
|
return nil, err
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if datautil.Contain(groupID, lvs.UIDList...) {
|
||||||
|
|
||||||
|
_, err := g.db.GetVersionSync(ctx, g.groupAndMemberVersionTableName(), groupID)
|
||||||
|
if err != nil {
|
||||||
|
if errs.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err := g.IncrSyncGroupAndMember(ctx, groupID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { // If the user is no longer in the group, return nil immediately
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
dataFetcher := datafetcher.NewDataFetcher(
|
dataFetcher := datafetcher.NewDataFetcher(
|
||||||
g.db,
|
g.db,
|
||||||
g.groupAndMemberVersionTableName(),
|
g.groupAndMemberVersionTableName(),
|
||||||
|
@ -98,3 +98,31 @@ func (ds *DataFetcher[T]) FetchMissingAndFillLocal(ctx context.Context, uids []s
|
|||||||
|
|
||||||
return localData, nil
|
return localData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FetchMissingAndCombineLocal fetches missing data from the server and combines it with local data without inserting it into the local database
|
||||||
|
func (ds *DataFetcher[T]) FetchMissingAndCombineLocal(ctx context.Context, uids []string) ([]T, error) {
|
||||||
|
localData, err := ds.FetchFromLocal(ctx, uids)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
localUIDSet := datautil.SliceSetAny(localData, ds.Key)
|
||||||
|
|
||||||
|
var missingUIDs []string
|
||||||
|
for _, uid := range uids {
|
||||||
|
if _, found := localUIDSet[uid]; !found {
|
||||||
|
missingUIDs = append(missingUIDs, uid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(missingUIDs) > 0 {
|
||||||
|
serverData, err := ds.fetchFromServer(ctx, missingUIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Combine local data with server data
|
||||||
|
localData = append(localData, serverData...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return localData, nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user