CKQuery slow with CKAssets

226 Views Asked by At

When I fetch for records with fields that are Strings (or others) it takes under 1 second:

 let query = CKQuery(recordType: "Messages", predicate: NSPredicate(format: "TRUEPREDICATE"))
    NSLog("Started fetching")
    self.publicDb.performQuery(query, inZoneWithID: nil) { (records, error) in
        NSLog("Finished fetching")
        print(records!.count)
    }

But, when this record type contains a CKAsset, the time for the query goes up to at least 3 seconds. This is not acceptable when I want to load an image that is 100kb. It's the same when I put the asset in as a reference and load it from there. What can I do to speed up queries for records that contain assets or is there any other way to store assets in a more efficient way?

1

There are 1 best solutions below

1
On

Use an operation and set the quality of service:

CKQueryOperation *queryOperation = [[CKQueryOperation alloc] initWithQuery:query];

queryOperation.qualityOfService = NSQualityOfServiceUserInitiated;

If you don't set qualityOfService, you will get the background level and it will be slow.