From bb40894778586799eac48ad80ff63fce99edd351 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 26 Dec 2022 12:09:57 -0500 Subject: [PATCH] Ensure all statuses are cached before returning --- Tusker/Screens/Timeline/TimelineViewController.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index 251bf1c9..bac71bda 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -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) {