From d8901b38f55c838983196118e62c330921334489 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 27 Jan 2023 21:49:34 -0500 Subject: [PATCH] Load timeline posts in pages of 40 --- .../Screens/Timeline/TimelineViewController.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index e36142dc..3b80c6d5 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -947,8 +947,11 @@ extension TimelineViewController { extension TimelineViewController { typealias TimelineItem = String // status ID + // the maximum mastodon will provide in a single request + private static let pageSize = 40 + func loadInitial() async throws -> [TimelineItem] { - let request = Client.getStatuses(timeline: timeline) + let request = Client.getStatuses(timeline: timeline, range: .count(TimelineViewController.pageSize)) let (statuses, _) = try await mastodonController.run(request) await withCheckedContinuation { continuation in @@ -965,7 +968,7 @@ extension TimelineViewController { guard case .status(id: let id, _, _) = dataSource.itemIdentifier(for: IndexPath(row: 0, section: statusesSection)) else { throw Error.noNewer } - let newer = RequestRange.after(id: id, count: nil) + let newer = RequestRange.after(id: id, count: TimelineViewController.pageSize) let request = Client.getStatuses(timeline: timeline, range: newer) let (statuses, _) = try await mastodonController.run(request) @@ -989,7 +992,7 @@ extension TimelineViewController { guard case .status(id: let id, _, _) = dataSource.itemIdentifier(for: IndexPath(row: snapshot.numberOfItems(inSection: .statuses) - 1, section: statusesSection)) else { throw Error.noNewer } - let older = RequestRange.before(id: id, count: nil) + let older = RequestRange.before(id: id, count: TimelineViewController.pageSize) let request = Client.getStatuses(timeline: timeline, range: older) let (statuses, _) = try await mastodonController.run(request) @@ -1020,13 +1023,13 @@ extension TimelineViewController { // not really the right error but w/e throw Error.noGap } - range = .before(id: id, count: nil) + range = .before(id: id, count: TimelineViewController.pageSize) case .below: guard gapIndexPath.row < statusItemsCount - 1, case .status(id: let id, _, _) = dataSource.itemIdentifier(for: IndexPath(row: gapIndexPath.row + 1, section: gapIndexPath.section)) else { throw Error.noGap } - range = .after(id: id, count: nil) + range = .after(id: id, count: TimelineViewController.pageSize) } let request = Client.getStatuses(timeline: timeline, range: range)