简体   繁体   English

如果结果限制小于1000,为什么我的CKQueryOperation只返回一个Cursor?

[英]Why will my CKQueryOperation only return a Cursor if the results limit is less than 1000?

CloudKit has about 2000 records that I am attempting to download. CloudKit有大约2000条我试图下载的记录。 I cannot get all of them to download, I looked at CloudKit CKQueryOperation doesn't get all records to get more than 100 results. 我无法让他们全部下载,我看着CloudKit CKQueryOperation并没有获得所有记录以获得超过100个结果。 Now I can get upto 999 to download, but if I set the results limit to 1000 or more it will fail randomly between 80-500. 现在我可以下载到999,但如果我将结果限制设置为1000或更高,它将在80-500之间随机失败。 Will I need to split these entries into different record types? 我是否需要将这些条目拆分为不同的记录类型?

private func checkForCloudData() {
    let query = CKQuery(recordType: "myRecordType", predicate: .init(value: true))
    let op = CKQueryOperation(query: query)

    op.qualityOfService = .userInitiated
    op.queuePriority = .veryHigh
    op.resultsLimit = 999

    op.recordFetchedBlock = { record in
        // fetched record
    }

    op.queryCompletionBlock =  { cursor, err in

        if cursor != nil {
            print(cursor!)

            self.performOperation(withOperation: CKQueryOperation(cursor: cursor!))
        }

        if err == nil {
            // handle complete download
        } else {
            if (err as! CKError).code == .limitExceeded {
                if cursor != nil {
                    self.performOperation(withOperation: CKQueryOperation(cursor: cursor!))
                    return
                }
                let newOperation = CKQueryOperation(query: query)
                newOperation.resultsLimit = op.resultsLimit
                newOperation.queuePriority = .veryHigh
                newOperation.qualityOfService = .userInitiated
                newOperation.recordFetchedBlock = op.recordFetchedBlock
                newOperation.queryCompletionBlock = op.queryCompletionBlock

                self.performOperation(withOperation: newOperation)
            }
        }

    }

    self.performOperation(withOperation: op)
}

private func performOperation(withOperation operation: CKQueryOperation) {
        publicDB.add(operation)
}

I believe that 400 is the the limit for a single operation, so you need to use cursor to get more records, and keep on doing that while returned cursor is not nil . 我相信400是单个操作的限制,因此您需要使用游标来获取更多记录,并在返回游标不nil时继续执行此操作。

See how it is done in RxCloudKit library' RecordFetcher - https://github.com/maxvol/RxCloudKit/blob/master/RxCloudKit/RecordFetcher.swift 看看它是如何在RxCloudKit库' RecordFetcher - https://github.com/maxvol/RxCloudKit/blob/master/RxCloudKit/RecordFetcher.swift

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CKQueryOperation queryCompletionBlock只运行3次 - CKQueryOperation queryCompletionBlock only runs 3 times 使用新的游标多次执行CKQueryOperation - Executing a CKQueryOperation multiple times with a new cursor 是否计算UITextView中的文本是否小于4 maximumNumberOfLines限制? - Calculating if text in UITextView is less than the 4 maximumNumberOfLines limit? CloudKit-每次运行相同查询时CKQueryOperation结果不同 - CloudKit - CKQueryOperation results different each time the same query is ran 如何使用CloudKit通过CKQueryOperation进行迭代查询,直到游标为nil? - How do I use CloudKit to query iteratively with CKQueryOperation until cursor is nil? 为什么UITableViewCell宽度小于UITableView宽度 - Why is UITableViewCell width less than UITableView width 为什么通过扩展使用的 flatMap 返回的结果与直接调用的结果不同? - Why does flatMap used via an extension return different results than when called directly? 如何从解析查询中获得1000多个结果? - How can I get more than 1000 results from a Parse query? 为什么我的 UISearchBar 没有更新结果? - Why is my UISearchBar not updating the results? 为什么我的搜索结果只有在我开始输入后才会显示? - Why do the results of my search only show up once I begin typing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM