forked from shadowfacts/Tusker
Ensure all statuses are cached before returning
This commit is contained in:
parent
24b3fa1e3f
commit
bb40894778
|
@ -353,15 +353,23 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
|||
guard !unloaded.isEmpty else {
|
||||
return
|
||||
}
|
||||
await withTaskGroup(of: Void.self) { group in
|
||||
let statuses = await withTaskGroup(of: Status?.self) { group -> [Status] in
|
||||
for id in unloaded {
|
||||
group.addTask { @MainActor in
|
||||
if let (status, _) = try? await self.mastodonController.run(Client.getStatus(id: id)) {
|
||||
self.mastodonController.persistentContainer.addOrUpdate(status: status)
|
||||
return status
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return await group.reduce(into: []) { partialResult, status in
|
||||
if let status {
|
||||
partialResult.append(status)
|
||||
}
|
||||
}
|
||||
}
|
||||
await mastodonController.persistentContainer.addAll(statuses: statuses)
|
||||
}
|
||||
|
||||
private func applyItemsToRestore(position: TimelinePosition) {
|
||||
|
|
Loading…
Reference in New Issue