mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-01 09:50:16 +00:00
Fix bug where sending an article's read status could delete its queued starred status.
This commit is contained in:
1 parent
41395fb9b7
commit
e5171cbb0b
6 files changed
+35
-22
No files matched your search
@@ -752,7 +752,7 @@ private extension FeedbinAccountDelegate {
|
||||
}
|
||||
|
||||
func sendArticleStatuses(_ statuses: [SyncStatus], apiCall: ([Int]) async throws -> Void) async throws -> Int {
|
||||
guard !statuses.isEmpty else {
|
||||
guard let key = statuses.first?.key else {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -764,12 +764,12 @@ private extension FeedbinAccountDelegate {
|
||||
for articleIDGroup in articleIDGroups {
|
||||
do {
|
||||
try await apiCall(articleIDGroup)
|
||||
await self.syncDatabase.deleteSelectedForProcessing(Set(articleIDGroup.map { String($0) }))
|
||||
await self.syncDatabase.deleteSelectedForProcessing(Set(articleIDGroup.map { String($0) }), key: key)
|
||||
sentCount += articleIDGroup.count
|
||||
} catch {
|
||||
savedError = error
|
||||
Self.logger.error("Feedbin: Article status sync call failed: \(error.localizedDescription)")
|
||||
await self.syncDatabase.resetSelectedForProcessing(Set(articleIDGroup.map { String($0) }))
|
||||
await self.syncDatabase.resetSelectedForProcessing(Set(articleIDGroup.map { String($0) }), key: key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -239,11 +239,11 @@ import Secrets
|
||||
let chunkIDs = Set(chunk)
|
||||
try await logRefreshPage(for: account, kind: .sendArticleStatuses, message: { _ in "\(chunkIDs.count) \(pairing.action.rawValue)" }, { try await caller.mark(chunkIDs, as: pairing.action) })
|
||||
}
|
||||
await syncDatabase.deleteSelectedForProcessing(articleIDs)
|
||||
await syncDatabase.deleteSelectedForProcessing(articleIDs, key: pairing.key)
|
||||
sentCount += articleIDs.count
|
||||
} catch {
|
||||
Self.logger.error("Feedly: Article status sync call failed: \(error.localizedDescription)")
|
||||
await syncDatabase.resetSelectedForProcessing(articleIDs)
|
||||
await syncDatabase.resetSelectedForProcessing(articleIDs, key: pairing.key)
|
||||
savedError = error
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -280,7 +280,7 @@ import os
|
||||
throttle: Bool,
|
||||
apiCall: (Set<String>) async throws -> Void)
|
||||
async throws -> Int {
|
||||
guard !statuses.isEmpty else {
|
||||
guard let key = statuses.first?.key else {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -292,12 +292,12 @@ import os
|
||||
for storyHashGroup in storyHashGroups {
|
||||
do {
|
||||
try await apiCall(Set(storyHashGroup))
|
||||
await syncDatabase.deleteSelectedForProcessing(Set(storyHashGroup))
|
||||
await syncDatabase.deleteSelectedForProcessing(Set(storyHashGroup), key: key)
|
||||
sentCount += storyHashGroup.count
|
||||
} catch {
|
||||
savedError = error
|
||||
Self.logger.error("NewsBlur: Story status sync call failed: \(error.localizedDescription)")
|
||||
await syncDatabase.resetSelectedForProcessing(Set(storyHashGroup))
|
||||
await syncDatabase.resetSelectedForProcessing(Set(storyHashGroup), key: key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -873,7 +873,7 @@ private extension ReaderAPIAccountDelegate {
|
||||
func sendArticleStatuses(_ statuses: Set<SyncStatus>, account: Account, label: String, apiCall: ([String]) async throws -> Void) async throws -> Int {
|
||||
Self.logger.debug("ReaderAPIAccountDelegate: sendArticleStatuses")
|
||||
|
||||
guard !statuses.isEmpty else {
|
||||
guard let key = statuses.first?.key else {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -884,7 +884,7 @@ private extension ReaderAPIAccountDelegate {
|
||||
let unsendableArticleIDs = Set(articleIDs.filter { !articleIDIsSendable($0) })
|
||||
if !unsendableArticleIDs.isEmpty {
|
||||
Self.logger.error("ReaderAPIAccountDelegate: dropping \(unsendableArticleIDs.count) unsendable article IDs from the status queue")
|
||||
await syncDatabase.deleteSelectedForProcessing(unsendableArticleIDs)
|
||||
await syncDatabase.deleteSelectedForProcessing(unsendableArticleIDs, key: key)
|
||||
}
|
||||
let sendableArticleIDs = articleIDs.filter { articleIDIsSendable($0) }
|
||||
|
||||
@@ -895,12 +895,12 @@ private extension ReaderAPIAccountDelegate {
|
||||
|
||||
do {
|
||||
try await logRefreshPage(for: account, kind: .sendArticleStatuses, message: { _ in "\(articleIDGroup.count) \(label)" }, { try await apiCall(articleIDGroup) })
|
||||
await syncDatabase.deleteSelectedForProcessing(Set(articleIDGroup))
|
||||
await syncDatabase.deleteSelectedForProcessing(Set(articleIDGroup), key: key)
|
||||
sentCount += articleIDGroup.count
|
||||
} catch {
|
||||
savedError = error
|
||||
Self.logger.error("ReaderAPIAccountDelegate: sendArticleStatuses — error \(error.localizedDescription)")
|
||||
await syncDatabase.resetSelectedForProcessing(Set(articleIDGroup))
|
||||
await syncDatabase.resetSelectedForProcessing(Set(articleIDGroup), key: key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,12 +55,14 @@ public actor SyncDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
public func resetSelectedForProcessing(_ articleIDs: Set<String>) {
|
||||
SyncStatusTable.resetSelectedForProcessing(articleIDs, database: database)
|
||||
/// Pass `key` when sending one status kind at a time. A nil key matches all kinds —
|
||||
/// correct only when every queued kind for these articleIDs was sent together.
|
||||
public func resetSelectedForProcessing(_ articleIDs: Set<String>, key: SyncStatus.Key? = nil) {
|
||||
SyncStatusTable.resetSelectedForProcessing(articleIDs, key: key, database: database)
|
||||
}
|
||||
|
||||
public func deleteSelectedForProcessing(_ articleIDs: Set<String>) {
|
||||
SyncStatusTable.deleteSelectedForProcessing(articleIDs, database: database)
|
||||
public func deleteSelectedForProcessing(_ articleIDs: Set<String>, key: SyncStatus.Key? = nil) {
|
||||
SyncStatusTable.deleteSelectedForProcessing(articleIDs, key: key, database: database)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,25 +66,36 @@ struct SyncStatusTable {
|
||||
database.executeUpdateInTransaction(updateSQL)
|
||||
}
|
||||
|
||||
static func resetSelectedForProcessing(_ articleIDs: Set<String>, database: FMDatabase) {
|
||||
// An articleID can have both a read row and a starred row queued. Callers that send
|
||||
// one status kind at a time must pass `key` so they don’t touch the other kind’s rows.
|
||||
|
||||
static func resetSelectedForProcessing(_ articleIDs: Set<String>, key: SyncStatus.Key?, database: FMDatabase) {
|
||||
guard !articleIDs.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
let parameters = articleIDs.map { $0 as AnyObject }
|
||||
var parameters = articleIDs.map { $0 as AnyObject }
|
||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(articleIDs.count))!
|
||||
let updateSQL = "update \(name) set selected = false where articleID in \(placeholders)"
|
||||
var updateSQL = "update \(name) set selected = false where articleID in \(placeholders)"
|
||||
if let key {
|
||||
updateSQL += " and key = ?"
|
||||
parameters.append(key.rawValue as AnyObject)
|
||||
}
|
||||
database.executeUpdateInTransaction(updateSQL, withArgumentsIn: parameters)
|
||||
}
|
||||
|
||||
static func deleteSelectedForProcessing(_ articleIDs: Set<String>, database: FMDatabase) {
|
||||
static func deleteSelectedForProcessing(_ articleIDs: Set<String>, key: SyncStatus.Key?, database: FMDatabase) {
|
||||
guard !articleIDs.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
let parameters = articleIDs.map { $0 as AnyObject }
|
||||
var parameters = articleIDs.map { $0 as AnyObject }
|
||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(articleIDs.count))!
|
||||
let deleteSQL = "delete from \(name) where selected = true and articleID in \(placeholders)"
|
||||
var deleteSQL = "delete from \(name) where selected = true and articleID in \(placeholders)"
|
||||
if let key {
|
||||
deleteSQL += " and key = ?"
|
||||
parameters.append(key.rawValue as AnyObject)
|
||||
}
|
||||
database.executeUpdateInTransaction(deleteSQL, withArgumentsIn: parameters)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user