perf: lazy hierarchical loading for game picker

Replace upfront loading of all games with lazy Sport → Team → Game
hierarchy. Games are now fetched per-team when expanded and cached
to prevent re-fetching. Also removes pagination workaround and
pre-computes groupings in ScheduleViewModel to avoid per-render work.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-12 20:19:46 -06:00
parent 9531ed1008
commit 37a1347ce3
5 changed files with 235 additions and 295 deletions

View File

@@ -112,28 +112,6 @@ final class TripCreationViewModel {
var availableGames: [RichGame] = []
var isLoadingGames: Bool = false
// MARK: - Game Pagination
private let gamePageSize = 50
var displayedAvailableGames: [RichGame] = []
private var currentGamePage = 0
var hasMoreAvailableGames: Bool {
displayedAvailableGames.count < availableGames.count
}
func loadInitialAvailableGames() {
currentGamePage = 0
displayedAvailableGames = Array(availableGames.prefix(gamePageSize))
}
func loadMoreAvailableGames() {
guard hasMoreAvailableGames else { return }
currentGamePage += 1
let start = currentGamePage * gamePageSize
let end = min(start + gamePageSize, availableGames.count)
displayedAvailableGames.append(contentsOf: availableGames[start..<end])
}
// Travel
var travelMode: TravelMode = .drive
var routePreference: RoutePreference = .balanced
@@ -298,9 +276,6 @@ final class TripCreationViewModel {
}
return RichGame(game: game, homeTeam: homeTeam, awayTeam: awayTeam, stadium: stadium)
}
// Initialize paginated display
loadInitialAvailableGames()
} catch {
viewState = .error("Failed to load schedule data: \(error.localizedDescription)")
}
@@ -526,9 +501,6 @@ final class TripCreationViewModel {
return RichGame(game: game, homeTeam: homeTeam, awayTeam: awayTeam, stadium: stadium)
}.sorted { $0.game.dateTime < $1.game.dateTime }
// Initialize paginated display
loadInitialAvailableGames()
} catch {
viewState = .error("Failed to load games: \(error.localizedDescription)")
}
@@ -569,8 +541,6 @@ final class TripCreationViewModel {
mustStopLocations = []
preferredCities = []
availableGames = []
displayedAvailableGames = []
currentGamePage = 0
isLoadingGames = false
currentPreferences = nil
allowRepeatCities = true