Change so that we only send 300 markers per request. Fixes #3711

This commit is contained in:
Maurice Parker 2022-10-28 15:53:26 -05:00
parent 6baee15007
commit 948b02d0ac

View File

@ -7,6 +7,7 @@
// //
import Foundation import Foundation
import RSCore
import RSWeb import RSWeb
import Secrets import Secrets
@ -820,6 +821,12 @@ extension FeedlyAPICaller: FeedlyMarkArticlesService {
fatalError("\(components) does not produce a valid URL.") fatalError("\(components) does not produce a valid URL.")
} }
let articleIdChunks = Array(articleIds).chunked(into: 300)
let dispatchGroup = DispatchGroup()
var groupError: Error? = nil
for articleIdChunk in articleIdChunks {
var request = URLRequest(url: url) var request = URLRequest(url: url)
request.httpMethod = "POST" request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: HTTPRequestHeader.contentType) request.addValue("application/json", forHTTPHeaderField: HTTPRequestHeader.contentType)
@ -827,7 +834,7 @@ extension FeedlyAPICaller: FeedlyMarkArticlesService {
request.addValue("OAuth \(accessToken)", forHTTPHeaderField: HTTPRequestHeader.authorization) request.addValue("OAuth \(accessToken)", forHTTPHeaderField: HTTPRequestHeader.authorization)
do { do {
let body = MarkerEntriesBody(action: action.actionValue, entryIds: Array(articleIds)) let body = MarkerEntriesBody(action: action.actionValue, entryIds: Array(articleIdChunk))
let encoder = JSONEncoder() let encoder = JSONEncoder()
let data = try encoder.encode(body) let data = try encoder.encode(body)
request.httpBody = data request.httpBody = data
@ -837,16 +844,25 @@ extension FeedlyAPICaller: FeedlyMarkArticlesService {
} }
} }
dispatchGroup.enter()
send(request: request, resultType: String.self, dateDecoding: .millisecondsSince1970, keyDecoding: .convertFromSnakeCase) { result in send(request: request, resultType: String.self, dateDecoding: .millisecondsSince1970, keyDecoding: .convertFromSnakeCase) { result in
switch result { switch result {
case .success(let (httpResponse, _)): case .success(let (httpResponse, _)):
if httpResponse.statusCode == 200 { if httpResponse.statusCode != 200 {
completion(.success(())) groupError = URLError(.cannotDecodeContentData)
} else {
completion(.failure(URLError(.cannotDecodeContentData)))
} }
case .failure(let error): case .failure(let error):
completion(.failure(error)) groupError = error
}
dispatchGroup.leave()
}
}
dispatchGroup.notify(queue: .main) {
if let groupError = groupError {
completion(.failure(groupError))
} else {
completion(.success(()))
} }
} }
} }