Skip to content

Open source CapCut alternative.

TypeScript

perf(ios): the analytics screen asks for its charts and its people at once

David Le70f7d194764d
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Analytics.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Analytics.swift
index 7d829323..c1fa53d0 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Analytics.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Analytics.swift
@@ -499,13 +499,20 @@ public final class AnalyticsModel {
/// A cancelled fetch is the screen closing, so it leaves the state alone.
public func refresh() async {
if case .failed = state { state = .loading }
+ // The numbers and the list come from the same rollup, so a refresh
+ // takes the list back to its first page — and both reads go out at
+ // once, so the screen waits for the slower one instead of for one
+ // after the other.
+ resetPeople()
+ async let people: Void = loadPeople(cursor: 0)
+ await loadSummary()
+ await people
+ }
+
+ private func loadSummary() async {
do {
let document = try await service.fetchAnalyticsSummary()
state = .loaded(AnalyticsSummary(document: document))
- // The numbers and the list come from the same rollup, so a refresh
- // takes the list back to its first page.
- resetPeople()
- await loadPeople(cursor: 0)
} catch AnalyticsError.noRollup {
state = .empty
} catch is CancellationError {
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/AnalyticsScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/AnalyticsScreen.swift
index dfe1f98c..9293c85a 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/AnalyticsScreen.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/AnalyticsScreen.swift
@@ -204,7 +204,9 @@ private struct PeopleSection: View {
.padding(.top, 8)
}
.padding(.vertical, 20)
- .task { await analytics.loadMorePeople() }
+ // The refresh that drew the charts is already fetching the first page;
+ // this asks only when the section came up to an empty list.
+ .task { if analytics.people.isEmpty { await analytics.loadMorePeople() } }
}
private var selectedLabel: String {