feat(sync): update CanonicalSyncService to use delta sync

- syncStadiums now passes lastSync to CloudKit fetch
- syncTeams simplified to single CloudKit call (not per-sport loop)
- syncGames removes 6-month date range, uses modificationDate delta

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-12 10:49:53 -06:00
parent 3bb903ab09
commit b89c0d58e2

View File

@@ -210,8 +210,8 @@ actor CanonicalSyncService {
context: ModelContext,
since lastSync: Date?
) async throws -> (updated: Int, skippedIncompatible: Int, skippedOlder: Int) {
// Use sync method that returns canonical IDs directly from CloudKit
let syncStadiums = try await cloudKitService.fetchStadiumsForSync()
// Delta sync: nil = all stadiums, Date = only modified since
let syncStadiums = try await cloudKitService.fetchStadiumsForSync(since: lastSync)
var updated = 0
var skippedIncompatible = 0
@@ -240,12 +240,8 @@ actor CanonicalSyncService {
context: ModelContext,
since lastSync: Date?
) async throws -> (updated: Int, skippedIncompatible: Int, skippedOlder: Int) {
// Use sync method that returns canonical IDs directly from CloudKit
var allSyncTeams: [CloudKitService.SyncTeam] = []
for sport in Sport.allCases {
let syncTeams = try await cloudKitService.fetchTeamsForSync(for: sport)
allSyncTeams.append(contentsOf: syncTeams)
}
// Single call for all teams with delta sync
let allSyncTeams = try await cloudKitService.fetchTeamsForSync(since: lastSync)
var updated = 0
var skippedIncompatible = 0
@@ -275,15 +271,8 @@ actor CanonicalSyncService {
context: ModelContext,
since lastSync: Date?
) async throws -> (updated: Int, skippedIncompatible: Int, skippedOlder: Int) {
// Use sync method that returns canonical IDs directly from CloudKit
let startDate = lastSync ?? Date()
let endDate = Calendar.current.date(byAdding: .month, value: 6, to: Date()) ?? Date()
let syncGames = try await cloudKitService.fetchGamesForSync(
sports: Set(Sport.allCases),
startDate: startDate,
endDate: endDate
)
// Delta sync: nil = all games, Date = only modified since
let syncGames = try await cloudKitService.fetchGamesForSync(since: lastSync)
var updated = 0
var skippedIncompatible = 0