CKFetchRecordChangesOperation returns junk data first

584 views Asked by At

When previousServerToken is null, CKFetchRecordChangesOperation seems to take several passes to download the first set of data, retrying until the moreComing flag is clear.

It isn't because there are too many records- In my testing I only have around 40 member records, each of which belong to one of the 6 groups.

The first pass gives two badly-formed member records; the second pass sometimes sends a few member records from a group that has not yet been downloaded, or nothing. Only after the third pass does it download all the remaining groups and members as expected.

Any ideas why this might be?

2

There are 2 answers

2
farktronix On BEST ANSWER

This can happen if the zone has had lots of records deleted in it. The server scans through all of the changes for the zone and then drops changes for records that have been deleted. Sometimes this can result in a batch of changes with zero record changes, but moreComing set to true.

Take a look at the new fetchAllChanges flag on CKFetchRecordZoneChangesOperation in iOS 10/macOS 10.12. CloudKit will pipeline fetch changes requests for you and you'll just see record changes and zone change tokens until everything in the zone has been fetched.

0
Peter Johnson On

This is the problem it caused, and what I had to do about it...

I have two types of record- groups, and members (which must have a group as their parent.)

The problem is that, although CloudKit normally returns parents of records first, it will only do this within a single batch.

Members might therefore be received before their parent group if it is in a different batch (which can happen if a group has been subsequently edited or renamed, as that moves it later in the processing order)

If you are using arrays on your device to represent the downloaded data, you therefore need to either cache members across a series of batches, and process them at the end (after all groups have been received,) or allow a record to create a temporary dummy group that is overwritten with that groups name and other data when it eventually arrives.