I am trying to create a specialised photo sharing social network using CloudKit alone. The app will never need to be non iOS, so on the surface Cloudkit has seemed like a perfect backend. However, I've found at random but semi frequent times, the loading of CKAssets from records can be very slow.
For example, at normal times, all of the assets can load in a second or less. However at other times, it can take from 5 to 15 seconds. This is on a public database using a fetch operation where I already have the record IDs. Here is my code that performs that:
mainDatabase.fetch(withRecordIDs: recordIDS, desiredKeys: ["image"]) { results in
var recordsToReturn: [CKRecord] = []
switch results {
case .success(let success):
for (_, result) in success {
switch result {
case .success(let record):
// If the result is success, append the record to the successfulRecords array
recordsToReturn.append(record)
break
case .failure(_):
break
}
}
completion(.success(recordsToReturn))
case .failure(let failure):
completion(.failure(failure))
}
}
}
Of note, I have also tried using a database operation at set the qualityOfService to userInitiated, which has had the same noticeable load times.
I have also tested this on different devices, on different networks (both cellular & different WiFi connections) and found also the same noticeable load times at random occurrences.
Therefore, what I am trying to find out:
- Is this an expected behaviour from using CloudKit?
- Is there a much better way to load CKAssets that would drastically help this load time issue?
- Is CloudKit even a viable option for this kind of app, or is it not designed for this type of app?
- What alternative approaches could be taken? (Eg. store assets in AWS...)
Would truly appreciate any feedback & guidance on this issue.