fix: group info get is empty when user not in this group.

This commit is contained in:
Gordon
2024-06-26 21:44:46 +08:00
parent 2fd7076c8c
commit 0e64d54534
2 changed files with 67 additions and 7 deletions

View File

@@ -98,3 +98,31 @@ func (ds *DataFetcher[T]) FetchMissingAndFillLocal(ctx context.Context, uids []s
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
}