From 145af4015902b1d120920052c7e41d89ed077464 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 3 Aug 2026 11:05:06 -0700 Subject: [PATCH 1/4] Don't let an in-flight status send hide a pending change from the refresh that would revert it. Fixes #4280. --- .../SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift b/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift index 86655a1d3..05eba1b3e 100644 --- a/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift +++ b/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift @@ -124,8 +124,11 @@ private extension SyncStatusTable { return SyncStatus(articleID: articleID, key: key, flag: flag, selected: selected) } + // Includes rows that are selected — a send in flight hasn’t been confirmed by the server yet, + // and skipping those let a concurrent refresh revert the change the send was carrying. + // static func selectPendingArticleIDs(_ statusKey: ArticleStatus.Key, database: FMDatabase) -> Set? { - let sql = "select articleID from \(name) where selected == false and key = \"\(statusKey.rawValue)\";" + let sql = "select articleID from \(name) where key = \"\(statusKey.rawValue)\";" guard let resultSet = database.executeQuery(sql, withArgumentsIn: nil) else { return nil } From 13aedbad297dd56338a6ee3a0ed535fed77b6b66 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 3 Aug 2026 11:07:55 -0700 Subject: [PATCH 2/4] Clear stale in-flight status selections at launch, so statuses queued when the app was killed get sent. --- .../Sources/Account/Feedbin/FeedbinAccountDelegate.swift | 5 +++++ .../Sources/Account/Feedly/FeedlyAccountDelegate.swift | 5 +++++ .../Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift | 5 +++++ .../Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index f886f615a..19e8f2ec5 100644 --- a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -449,6 +449,11 @@ public enum FeedbinAccountDelegateError: String, Error, Sendable { func accountDidInitialize() { credentials = try? account?.retrieveCredentials(type: .basic) + + // A send in progress when the app was killed left its statuses selected. Clear them so + // they get sent, instead of waiting for the next selectForProcessing to pick them up. + // + syncDatabase.resetAllSelectedForProcessing() } func accountWillBeDeleted() { diff --git a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index b6a6aa5e8..d50bc90ff 100644 --- a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -637,6 +637,11 @@ import Secrets } Self.logger.debug("FeedlyAccountDelegate: accountDidInitialize") credentials = try? account.retrieveCredentials(type: .oauthAccessToken) + + // A send in progress when the app was killed left its statuses selected. Clear them so + // they get sent, instead of waiting for the next selectForProcessing to pick them up. + // + syncDatabase.resetAllSelectedForProcessing() } func accountWillBeDeleted() { diff --git a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index dcd328f07..15a1eccc6 100644 --- a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -511,6 +511,11 @@ import Secrets func accountDidInitialize() { credentials = try? account?.retrieveCredentials(type: .newsBlurSessionID) + + // A send in progress when the app was killed left its statuses selected. Clear them so + // they get sent, instead of waiting for the next selectForProcessing to pick them up. + // + syncDatabase.resetAllSelectedForProcessing() } func accountWillBeDeleted() { diff --git a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 36f97bae1..184072312 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -677,6 +677,11 @@ final class ReaderAPIAccountDelegate: AccountDelegate { return } retrieveCredentialsIfNeeded(account) + + // A send in progress when the app was killed left its statuses selected. Clear them so + // they get sent, instead of waiting for the next selectForProcessing to pick them up. + // + syncDatabase.resetAllSelectedForProcessing() } func accountWillBeDeleted() { From 2441263c6e267ab8739a78cf5b4e8e757a2a1161 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 3 Aug 2026 11:13:39 -0700 Subject: [PATCH 3/4] =?UTF-8?q?Mark=20only=20the=20rows=20actually=20being?= =?UTF-8?q?=20sent=20as=20selected,=20so=20a=20limited=20batch=20can?= =?UTF-8?q?=E2=80=99t=20delete=20a=20queued=20status=20it=20never=20sent.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SyncDatabase/SyncStatusTable.swift | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift b/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift index 05eba1b3e..f7d4bb117 100644 --- a/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift +++ b/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift @@ -14,17 +14,14 @@ import RSDatabaseObjC struct SyncStatusTable { static let name = "syncStatus" + // Selects first, then marks just the rows being returned. Marking every row would flag rows + // past the limit as in-flight, and `deleteSelectedForProcessing` with a nil key would then + // delete a queued status that was never sent. static func selectForProcessing(limit: Int?, database: FMDatabase) -> Set? { database.beginTransaction() - let updateSQL = "update \(name) set selected = true" - guard database.executeUpdate(updateSQL, withArgumentsIn: nil) else { - database.rollback() - return nil - } - let selectSQL = { - var sql = "select * from \(name) where selected == true" + var sql = "select * from \(name)" if let limit { sql = "\(sql) limit \(limit)" } @@ -37,10 +34,28 @@ struct SyncStatusTable { } let statuses = resultSet.mapToSet(statusWithRow) + guard !statuses.isEmpty else { + database.commit() + return statuses + } + + // An articleID can have both a read row and a starred row, so match on the pair. + var parameters = [AnyObject]() + let conditions = statuses.map { status -> String in + parameters.append(status.articleID as AnyObject) + parameters.append(status.key.rawValue as AnyObject) + return "(articleID = ? and key = ?)" + } + + let updateSQL = "update \(name) set selected = true where \(conditions.joined(separator: " or "))" + guard database.executeUpdate(updateSQL, withArgumentsIn: parameters) else { + database.rollback() + return nil + } database.commit() - return statuses + return Set(statuses.map { SyncStatus(articleID: $0.articleID, key: $0.key, flag: $0.flag, selected: true) }) } static func selectPendingCount(database: FMDatabase) -> Int? { From 1efda2e375ab8dbad2c62348f7198a1f8369e117 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 3 Aug 2026 11:17:54 -0700 Subject: [PATCH 4/4] Fix type-check time failure. --- Mac/MainWindow/AddFeed/AddFeedWindowController.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Mac/MainWindow/AddFeed/AddFeedWindowController.swift b/Mac/MainWindow/AddFeed/AddFeedWindowController.swift index cbfa2d890..2f571fa63 100644 --- a/Mac/MainWindow/AddFeed/AddFeedWindowController.swift +++ b/Mac/MainWindow/AddFeed/AddFeedWindowController.swift @@ -137,7 +137,9 @@ private extension AddFeedWindowController { } func selectedContainer() -> Container? { - guard folderPopupButton.selectedItem?.isEnabled ?? false else { return nil } - return folderPopupButton.selectedItem?.representedObject as? Container + guard let selectedItem = folderPopupButton.selectedItem, selectedItem.isEnabled else { + return nil + } + return selectedItem.representedObject as? Container } }