From b89c0d58e29dbef8a34114735471ec477acff872 Mon Sep 17 00:00:00 2001 From: Trey t Date: Mon, 12 Jan 2026 10:49:53 -0600 Subject: [PATCH] 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 --- .../Core/Services/CanonicalSyncService.swift | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/SportsTime/Core/Services/CanonicalSyncService.swift b/SportsTime/Core/Services/CanonicalSyncService.swift index e4a8afb..a2c5501 100644 --- a/SportsTime/Core/Services/CanonicalSyncService.swift +++ b/SportsTime/Core/Services/CanonicalSyncService.swift @@ -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