Don't chunk entries at the caller level because it is already done in the delegate

This commit is contained in:
Maurice Parker 2020-10-28 16:16:15 -05:00
parent 31607414f6
commit aecf90f9f8
1 changed files with 17 additions and 32 deletions

View File

@ -576,19 +576,13 @@ final class ReaderAPICaller: NSObject {
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
let chunkedArticleIds = articleIDs.chunked(into: 200)
let group = DispatchGroup()
var groupEntries = [ReaderAPIEntry]()
var groupError: Error? = nil
for articleIDChunk in chunkedArticleIds {
let itemFetchParameters = articleIDChunk.map({ articleID -> String in
return "i=tag:google.com,2005:reader/item/\(articleID)"
// Get ids from above into hex representation of value
let idsToFetch = articleIDs.map({ (reference) -> String in
return "i=tag:google.com,2005:reader/item/\(reference)"
}).joined(separator:"&")
let postData = "T=\(token)&output=json&\(itemFetchParameters)".data(using: String.Encoding.utf8)
let postData = "T=\(token)&output=json&\(idsToFetch)".data(using: String.Encoding.utf8)
group.enter()
self.transport.send(request: request, method: HTTPMethod.post, data: postData!, resultType: ReaderAPIEntryWrapper.self, completion: { (result) in
switch result {
case .success(let (_, entryWrapper)):
@ -596,22 +590,13 @@ final class ReaderAPICaller: NSObject {
completion(.failure(ReaderAPIAccountDelegateError.invalidResponse))
return
}
groupEntries.append(contentsOf: entryWrapper.entries)
group.leave()
completion(.success((entryWrapper.entries)))
case .failure(let error):
groupError = error
group.leave()
completion(.failure(error))
}
})
}
group.notify(queue: DispatchQueue.main) {
if let error = groupError {
completion(.failure(error))
} else {
completion(.success(groupEntries))
}
}
case .failure(let error):
completion(.failure(error))