← All repositories

crossmate

A collaborative crossword app for iPhone and iPad

git clone https://code.inqk.net/crossmate.git


commit 30f36a0b511561736809b18f25eb025ccd815c53
parent 452f858ec29608bf522482d1eca19c694b9ca907
Author: Michael Camilleri <[email protected]>
Date:   Fri,  8 May 2026 22:25:14 +0900

Use more targeted CloudKit fetches

Diffstat

MCrossmate/Services/AppServices.swift | 6+++---
MCrossmate/Sync/SyncEngine.swift | 23+++++++++++++++--------

2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/Crossmate/Services/AppServices.swift b/Crossmate/Services/AppServices.swift

@@ -277,11 +277,11 @@ final class AppServices {
         guard await ensureICloudSyncStarted() else { return }
         syncMonitor.note("remote notification: \(summary)")
         if let target = currentPuzzleFetchTarget() {
-            await syncMonitor.run("remote-notification current-zone fetch") {
+            await syncMonitor.run("remote-notification fetch") {
                 try await syncEngine.fetchChanges(
-                    source: "push-current-zone",
+                    source: "push",
                     targetDatabase: target.database,
-                    zoneIDs: [target.zoneID]
+                    prioritizedZoneIDs: [target.zoneID]
                 )
             }
         } else {

diff --git a/Crossmate/Sync/SyncEngine.swift b/Crossmate/Sync/SyncEngine.swift

@@ -371,30 +371,37 @@ actor SyncEngine {
     func fetchChanges(
         source: String = "manual",
         targetDatabase: CKDatabase.Scope? = nil,
-        zoneIDs: [CKRecordZone.ID] = []
+        prioritizedZoneIDs: [CKRecordZone.ID] = []
     ) async throws {
         currentFetchSource = source
         defer { currentFetchSource = nil }
-        let options = zoneIDs.isEmpty
-            ? CKSyncEngine.FetchChangesOptions()
-            : CKSyncEngine.FetchChangesOptions(scope: .zoneIDs(zoneIDs))
 
         switch targetDatabase {
         case .private:
-            try await privateEngine?.fetchChanges(options)
+            try await privateEngine?.fetchChanges(fetchOptions(prioritizedZoneIDs: prioritizedZoneIDs))
         case .shared:
-            try await sharedEngine?.fetchChanges(options)
+            try await sharedEngine?.fetchChanges(fetchOptions(prioritizedZoneIDs: prioritizedZoneIDs))
         case .public:
             return
         case .none:
-            async let p: Void = privateEngine?.fetchChanges(options) ?? ()
-            async let s: Void = sharedEngine?.fetchChanges(options) ?? ()
+            let privateOptions = fetchOptions(prioritizedZoneIDs: prioritizedZoneIDs)
+            let sharedOptions = fetchOptions(prioritizedZoneIDs: prioritizedZoneIDs)
+            async let p: Void = privateEngine?.fetchChanges(privateOptions) ?? ()
+            async let s: Void = sharedEngine?.fetchChanges(sharedOptions) ?? ()
             _ = try await (p, s)
         case .some:
             return
         }
     }
 
+    private func fetchOptions(
+        prioritizedZoneIDs: [CKRecordZone.ID]
+    ) -> CKSyncEngine.FetchChangesOptions {
+        var options = CKSyncEngine.FetchChangesOptions()
+        options.prioritizedZoneIDs = prioritizedZoneIDs
+        return options
+    }
+
     func pushChanges() async throws {
         async let p: Void = privateEngine?.sendChanges() ?? ()
         async let s: Void = sharedEngine?.sendChanges() ?? ()