CKQueryOperation right after CKModifyRecordsOperation

Hello,

in my app I need to fetch all records in a custom zone (~12) shortly after writing them to the private db. The operations are all synchronized via dependencies. The data written to the cloud via CKModifyRecordsOperation is there as seen in the dashboard and verified by correct results in the completion handler. My problem is that CKQueryOperation doesn't return records just written. If somehow I delay the call to CKQueryOperation then it works. This almost sounds like there's somekind of latency between writing and reading.


I've reviewed all the documentation and other than the operation based dependency mechanism I see no way of synchronizing reads and writes.


What am I missing?


Plasse help!


Ramon.

Replies

The CKModifyRecordsOperation is handing you back the modified records (including updated change tags). Maybe you can skip the query operation in favor of the new data returned from the modify operation?

Yes, in this particular case I could do as you suggest. But that is not always be possible. If I save 12 records and there are (lets say) 5 records already in the cloud then a subsequent reading of all the records should return 17. My feeling is that this is a fundamental issue that needs to be understood. I found an old thread in SO which appears to be the a similar issue; see


https://stackoverflow.com/questions/26375113/cloudkit-not-returning-the-most-recent-data


Ramon.

Hello, I found more evidence that there's some undetermined latency when using CloudKit. One thread in SO suggested stitching records to avoid the latency problem. The "stitching" technique was defintely possible in my case; so, I re-wrote my code to take advantage of that technique. And that, basically, bypasses the latency altogther by avoiding the need to load all records.


Here's the SO thread: CloudKit Record Stitching.


MendelK, your reply helped me somewhat since it pointed me to consider using the existing records. Thanks!