Fix status syncing bug with > 999 sync statuses in the database (hitting SQLite limit).

This commit is contained in:
Brent Simmons committed 2026-08-30 20:28:19 -07:00
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()