Observers on system:data_sync_info result in the callback triggering every 500ms even when the result remains the same. This frequency can be
configured using the live_query_system_collection_refresh_interval system parameter.
Track several commits and watch them sync in order:
Copy
Ask AI
var pendingCommits: [Int64] = []// Make several commitslet result1 = try await ditto.store.execute( query: "UPDATE inventory SET quantity = quantity - 1 WHERE _id = 'item-1'")if let commitId1 = result1.commitID { pendingCommits.append(commitId1)}let result2 = try await ditto.store.execute( query: "INSERT INTO orders DOCUMENTS (:order)", arguments: ["order": ["_id": "order-789", "status": "pending"]])if let commitId2 = result2.commitID { pendingCommits.append(commitId2)}// Watch them synclet observer = ditto.store.registerObserver( query: "SELECT * FROM system:data_sync_info WHERE is_ditto_server = true") { result in guard let item = result.items.first, let documents = item.value["documents"] as? [String: Any], let syncedUpTo = documents["synced_up_to_local_commit_id"] as? Int64 else { return } // Check which commits have synced var syncedCount = 0 for commitId in pendingCommits { if syncedUpTo >= commitId { print("Commit \(commitId) synced") syncedCount += 1 } else { break } } // Remove synced commits if syncedCount > 0 { pendingCommits.removeFirst(syncedCount) print("\(pendingCommits.count) commits remaining") }}
Track sync progress to any peer (not just cloud servers):
Copy
Ask AI
// Check sync to a specific peer devicelet syncResult = try await ditto.store.execute( query: "SELECT * FROM system:data_sync_info WHERE _id = 'peer-device-456'")if let item = syncResult.items.first, let documents = item.value["documents"] as? [String: Any], let peerSyncedUpTo = documents["synced_up_to_local_commit_id"] as? Int64 { print("Peer has synced up to commit \(peerSyncedUpTo)")}