Reset any sync statuses that may be left around after a crash or force quit

This commit is contained in:
Maurice Parker 2020-04-27 19:21:49 -05:00
parent 0944264326
commit 1ce63860cf
3 changed files with 24 additions and 0 deletions

View File

@ -460,6 +460,8 @@ final class CloudKitAccountDelegate: AccountDelegate {
accountZone.delegate = CloudKitAcountZoneDelegate(account: account, refreshProgress: refreshProgress, articlesZone: articlesZone) accountZone.delegate = CloudKitAcountZoneDelegate(account: account, refreshProgress: refreshProgress, articlesZone: articlesZone)
articlesZone.delegate = CloudKitArticlesZoneDelegate(account: account, database: database, articlesZone: articlesZone) articlesZone.delegate = CloudKitArticlesZoneDelegate(account: account, database: database, articlesZone: articlesZone)
database.resetAllSelectedForProcessing()
// Check to see if this is a new account and initialize anything we need // Check to see if this is a new account and initialize anything we need
if account.externalID == nil { if account.externalID == nil {
accountZone.findOrCreateAccount() { result in accountZone.findOrCreateAccount() { result in

View File

@ -52,6 +52,10 @@ public struct SyncDatabase {
syncStatusTable.selectPendingStarredStatusArticleIDs(completion: completion) syncStatusTable.selectPendingStarredStatusArticleIDs(completion: completion)
} }
public func resetAllSelectedForProcessing(completion: DatabaseCompletionBlock? = nil) {
syncStatusTable.resetAllSelectedForProcessing(completion: completion)
}
public func resetSelectedForProcessing(_ articleIDs: [String], completion: DatabaseCompletionBlock? = nil) { public func resetSelectedForProcessing(_ articleIDs: [String], completion: DatabaseCompletionBlock? = nil) {
syncStatusTable.resetSelectedForProcessing(articleIDs, completion: completion) syncStatusTable.resetSelectedForProcessing(articleIDs, completion: completion)
} }

View File

@ -91,6 +91,24 @@ struct SyncStatusTable: DatabaseTable {
selectPendingArticleIDsAsync(.starred, completion) selectPendingArticleIDsAsync(.starred, completion)
} }
func resetAllSelectedForProcessing(completion: DatabaseCompletionBlock? = nil) {
queue.runInTransaction { databaseResult in
func makeDatabaseCall(_ database: FMDatabase) {
let updateSQL = "update syncStatus set selected = false"
database.executeUpdate(updateSQL, withArgumentsIn: nil)
}
switch databaseResult {
case .success(let database):
makeDatabaseCall(database)
callCompletion(completion, nil)
case .failure(let databaseError):
callCompletion(completion, databaseError)
}
}
}
func resetSelectedForProcessing(_ articleIDs: [String], completion: DatabaseCompletionBlock? = nil) { func resetSelectedForProcessing(_ articleIDs: [String], completion: DatabaseCompletionBlock? = nil) {
queue.runInTransaction { databaseResult in queue.runInTransaction { databaseResult in