crossmate

A collaborative crossword app for iOS
Log | Files | Refs | LICENSE

commit a65825bc8d781fc2ccce66b7ee93d6af18dff63a
parent e3b9b5effc7c5ab89b32ada395f0fbb2e23855ff
Author: Michael Camilleri <[email protected]>
Date:   Thu,  7 May 2026 06:58:18 +0900

Replace in-memory engines on reset sync state

Diffstat:
MCrossmate/Sync/SyncEngine.swift | 22++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/Crossmate/Sync/SyncEngine.swift b/Crossmate/Sync/SyncEngine.swift @@ -463,8 +463,13 @@ actor SyncEngine { return saved } - /// Clears the saved state for both engines so the next `start()` creates - /// fresh instances. Pending records already in CloudKit are unaffected. + /// Clears the saved state for both engines and replaces the in-memory + /// engine instances so subsequent fetches walk every zone from scratch. + /// Clearing the persisted state alone is ineffective: the running engines + /// hold their tokens in memory and the next `stateUpdate` event saves + /// those tokens back, so the wipe is undone before the user can act on it. + /// Pending records already in CloudKit are unaffected. Locally-unconfirmed + /// moves are re-enqueued so the new engines push them on the next cycle. func resetSyncState() async { let ctx = persistence.container.newBackgroundContext() ctx.performAndWait { @@ -473,6 +478,19 @@ actor SyncEngine { entity.ckSharedEngineState = nil try? ctx.save() } + privateEngine = CKSyncEngine(CKSyncEngine.Configuration( + database: container.privateCloudDatabase, + stateSerialization: nil, + delegate: self + )) + sharedEngine = CKSyncEngine(CKSyncEngine.Configuration( + database: container.sharedCloudDatabase, + stateSerialization: nil, + delegate: self + )) + pendingPings = [:] + loggedFirstSharedPushPayload = false + _ = enqueueUnconfirmedMoves() } // MARK: - Private helpers