My schema is as follows
RecordType: OwnedEvents contains an element called "Owner". This Owner element points to CKReference created from a RecordType of type "OwnedEvents".
I have N OwnedEvents objects all pointing to one Owner object.
When I execute a query to retrieve all the records that point a given Owner object, I see that, in some cases, the query does not return all the records that point to it (it does return it in most cases). It also does not return an error in the completion block. When I go to the CloudKit dashboard, I see that all OwnedEvents objects are pointing to the same and correct Owner object as expected. The code I am using to retrieve is below.
My questions are:
Is this kind of "silent" failure expected? I.e Do I need to identify this and recover? OR Am I doing something wrong in my query?
Is there any way to say the query must return an error if not all records matching the criterion are retrieved? (i.e an atomic version of fetch..I guess not, since it is tough to know ahead of time what the expected number of matching records is, but I am wondering if there is something I can specify in the fetch or in the schema that hints at min number of records expected in the fetch result).
Is it more efficient to fetch using a predicate formed using a reference compared to fetch that uses a predicate of the form "Get all records of type OwnedEvents with Column X > N1 and Column X
- The reference is pointed to be same set of records, N1...N2
- I.e If the reference based retrieval is going to be unreliable I might as well go away from it and take a brute force approach, if it is not any faster. At least in latter I have a easy way of identifying errors
Code used
CKReference* recordToMatch = [[CKReference alloc] initWithRecordID:eventCollectionID
action:CKReferenceActionDeleteSelf]; //eventCollectionID is recordID of Record of type Owner
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"Owner == %@", recordToMatch];
// Create the query object.
CKQuery* query = [[CKQuery alloc] initWithRecordType:@"OwnedEvents" predicate:predicate];
CKQueryOperation *queryObject = [[CKQueryOperation alloc] initWithQuery:query] ;
queryObject.queryCompletionBlock = ^(CKQueryCursor * cursor, NSError * operationError) {
if(operationError)
{
DDLogError(@"Error %@ occured during query",operationError) ;
}
else if(cursor)
{
DDLogVerbose(@"Not all objects satisfying the query were returned. Need to get next batch") ;
//To do fetch remaining entries
CKQueryOperation *queryObject = [[CKQueryOperation alloc] initWithCursor:cursor] ;
//Execute another query with this object
}
else
{
DDLogVerbose(@"All objects satisfying the query were returned") ;
//Take appropriate action with rcvd data
}
} ;
queryObject.recordFetchedBlock = ^(CKRecord *record) {
DDLogVerbose(@"Received record with seq Num: %@, type",record[@"SequenceNumber"],record[@"EventType"]) ;
//Check if items are in sequence
} ;
[self.publicDatabase addOperation:queryObject] ;