fix: group info get is empty when user not in this group.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user