mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 08:17:16 +00:00
Fix status syncing bug with > 999 sync statuses in the database (hitting SQLite limit).
This commit is contained in:
1 parent
4b6c797e9c
commit
4ed99b52da
1 file changed
+16
-12
@@ -39,18 +39,22 @@ struct SyncStatusTable {
|
||||
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
|
||||
// An articleID can have both a read row and a starred row, so match on the pair —
|
||||
// grouping by key means each statement touches only that key’s articleIDs.
|
||||
let statusesByKey = Dictionary(grouping: statuses, by: \.key)
|
||||
for (key, statusesForKey) in statusesByKey {
|
||||
let articleIDs = statusesForKey.map { $0.articleID }
|
||||
guard let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(articleIDs.count)) else {
|
||||
database.rollback()
|
||||
return nil
|
||||
}
|
||||
var parameters = articleIDs.map { $0 as AnyObject }
|
||||
parameters.append(key.rawValue as AnyObject)
|
||||
let updateSQL = "update \(name) set selected = true where articleID in \(placeholders) and key = ?"
|
||||
guard database.executeUpdate(updateSQL, withArgumentsIn: parameters) else {
|
||||
database.rollback()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
database.commit()
|
||||
|
||||
Reference in new issue
Block a user