From f5845b9d124370ecd9f7dca36037cc06d7b7a2e7 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 3 Aug 2026 14:19:24 -0700 Subject: [PATCH] Coalesce overlapping Feedly status sends into one in-flight task and drop the racy bulk selection reset. --- .../Feedly/FeedlyAccountDelegate.swift | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index bcb631eee..ef4bea41b 100644 --- a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -94,6 +94,10 @@ import Secrets private var lastNoChangeSyncDate: Date? private static let noChangeBackoffInterval: TimeInterval = 30 * 60 + // The refresh, the status-sync timer, and the markArticles background flush can all + // start a status send. Overlapping sends would select and post the same queued rows. + private var statusSendTask: Task? + // The refresh timer, background refresh, and the Refresh command can all fire // refreshAll — overlapping runs double the request volume and corrupt progress. private var refreshAllIsRunning = false @@ -280,6 +284,20 @@ import Secrets /// Sends queued local status changes upstream. Returns the count successfully sent. private func sendArticleStatusReturningCount(for account: Account) async throws -> Int { + if let statusSendTask { + return try await statusSendTask.value + } + let task = Task { () -> Int in + defer { + statusSendTask = nil + } + return try await performStatusSend(for: account) + } + statusSendTask = task + return try await task.value + } + + private func performStatusSend(for account: Account) async throws -> Int { Self.logger.info("Feedly: Sending article statuses") defer { Self.logger.info("Feedly: Finished sending article statuses") @@ -361,10 +379,8 @@ import Secrets } if let savedError { - if rateLimiter.isRateLimitError(savedError) { - // Pairings skipped after a rate limit stay queued — clear their in-progress mark. - syncDatabase.resetAllSelectedForProcessing() - } + // Rows of pairings skipped after a rate limit stay selected — harmless, + // since the next selectForProcessing claims them again. throw savedError } return sentCount