mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 00:04:25 +00:00
Use conditional GET for Reader API tag and subscription lists, and skip the whole status reconcile — not just the status downloads — when near the Inoreader API quota.
This commit is contained in:
1 parent
a479f03cf5
commit
e69cb835aa
2 files changed
+34
-11
No files matched your search
@@ -131,14 +131,22 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
try? await sendArticleStatus()
|
||||
refreshProgress.completeTask()
|
||||
|
||||
let articleIDs = try await account.logActivity(kind: .fetchArticleIDs, detail: "All articles", successMessage: { "\($0.count) article IDs" }, {
|
||||
try await caller.retrieveItemIDs(type: .allForAccount, pageHandler: articleIDPageHandler(for: account, kind: .fetchArticleIDs))
|
||||
})
|
||||
refreshProgress.completeTask()
|
||||
// The mark-as-read of all fetched article IDs and the unread download that
|
||||
// corrects it are a pair — skipping just the second half would leave new
|
||||
// articles wrongly marked read. Skip or run the whole reconcile together.
|
||||
if shouldSkipStatusDownloadsToConserveQuota() {
|
||||
refreshProgress.completeTask()
|
||||
refreshProgress.completeTask()
|
||||
} else {
|
||||
let articleIDs = try await account.logActivity(kind: .fetchArticleIDs, detail: "All articles", successMessage: { "\($0.count) article IDs" }, {
|
||||
try await caller.retrieveItemIDs(type: .allForAccount, pageHandler: articleIDPageHandler(for: account, kind: .fetchArticleIDs))
|
||||
})
|
||||
refreshProgress.completeTask()
|
||||
|
||||
_ = await account.markAsReadAsync(articleIDs: Set(articleIDs))
|
||||
try? await refreshArticleStatus()
|
||||
refreshProgress.completeTask()
|
||||
_ = await account.markAsReadAsync(articleIDs: Set(articleIDs))
|
||||
try? await refreshArticleStatus()
|
||||
refreshProgress.completeTask()
|
||||
}
|
||||
|
||||
await refreshMissingArticles(account)
|
||||
refreshProgress.reset()
|
||||
|
||||
@@ -41,6 +41,11 @@ struct ReaderAPIUsageLimits {
|
||||
case readingList = "user/-/state/com.google/reading-list"
|
||||
}
|
||||
|
||||
private struct ConditionalGetKeys {
|
||||
static let subscriptions = "subscriptions"
|
||||
static let tags = "tags"
|
||||
}
|
||||
|
||||
private enum ReaderAPIEndpoints: String {
|
||||
case login = "/accounts/ClientLogin"
|
||||
case token = "/reader/api/0/token"
|
||||
@@ -203,10 +208,13 @@ struct ReaderAPIUsageLimits {
|
||||
throw WebserviceError.noURL
|
||||
}
|
||||
|
||||
var request = URLRequest(url: callURL, readerAPICredentials: credentials)
|
||||
let conditionalGet = accountSettings?.conditionalGetInfo(for: ConditionalGetKeys.tags)
|
||||
var request = URLRequest(url: callURL, readerAPICredentials: credentials, conditionalGet: conditionalGet)
|
||||
addVariantHeaders(&request)
|
||||
|
||||
let (_, wrapper) = try await session.send(request: request, resultType: ReaderAPITagContainer.self)
|
||||
// A 304 Not Modified comes back with an empty body, so this returns nil — callers skip syncing.
|
||||
let (response, wrapper) = try await session.send(request: request, resultType: ReaderAPITagContainer.self)
|
||||
storeConditionalGet(key: ConditionalGetKeys.tags, headers: response.allHeaderFields)
|
||||
return wrapper?.tags
|
||||
}
|
||||
|
||||
@@ -268,11 +276,14 @@ struct ReaderAPIUsageLimits {
|
||||
throw WebserviceError.noURL
|
||||
}
|
||||
|
||||
var request = URLRequest(url: callURL, readerAPICredentials: credentials)
|
||||
let conditionalGet = accountSettings?.conditionalGetInfo(for: ConditionalGetKeys.subscriptions)
|
||||
var request = URLRequest(url: callURL, readerAPICredentials: credentials, conditionalGet: conditionalGet)
|
||||
addVariantHeaders(&request)
|
||||
|
||||
do {
|
||||
let (_, container) = try await session.send(request: request, resultType: ReaderAPISubscriptionContainer.self)
|
||||
// A 304 Not Modified comes back with an empty body, so this returns nil — callers skip syncing.
|
||||
let (response, container) = try await session.send(request: request, resultType: ReaderAPISubscriptionContainer.self)
|
||||
storeConditionalGet(key: ConditionalGetKeys.subscriptions, headers: response.allHeaderFields)
|
||||
return container?.subscriptions
|
||||
} catch {
|
||||
logger.error("ReaderAPICaller: retrieveSubscriptions — error calling API: \(error.localizedDescription)")
|
||||
@@ -632,6 +643,10 @@ private extension ReaderAPICaller {
|
||||
|
||||
private static let defaultUsageLimitsResetAfter: TimeInterval = 60 * 60 * 24
|
||||
|
||||
private func storeConditionalGet(key: String, headers: [AnyHashable: Any]) {
|
||||
accountSettings?.setConditionalGetInfo(HTTPConditionalGetInfo(headers: headers), for: key)
|
||||
}
|
||||
|
||||
private func noteUsageLimits(from response: HTTPURLResponse) {
|
||||
guard let usageValue = response.value(forHTTPHeaderField: UsageLimitHeader.zone1Usage), let usage = Int(usageValue),
|
||||
let limitValue = response.value(forHTTPHeaderField: UsageLimitHeader.zone1Limit), let limit = Int(limitValue), limit > 0 else {
|
||||
|
||||
Reference in new issue
Block a user