Change so that we fire off status update immediately if the number of pending status changes exceeds 100. Issue #658

This commit is contained in:
Maurice Parker 2019-05-27 12:03:12 -05:00
parent fcb2fa3ebc
commit 61f9a66d74
3 changed files with 25 additions and 0 deletions

View File

@ -472,6 +472,10 @@ final class FeedbinAccountDelegate: AccountDelegate {
} }
database.insertStatuses(syncStatuses) database.insertStatuses(syncStatuses)
if database.selectPendingCount() > 100 {
sendArticleStatus(for: account) {}
}
return account.update(articles, statusKey: statusKey, flag: flag) return account.update(articles, statusKey: statusKey, flag: flag)
} }

View File

@ -31,6 +31,10 @@ public final class SyncDatabase {
return syncStatusTable.selectForProcessing() return syncStatusTable.selectForProcessing()
} }
public func selectPendingCount() -> Int {
return syncStatusTable.selectPendingCount()
}
public func resetSelectedForProcessing(_ articleIDs: [String]) { public func resetSelectedForProcessing(_ articleIDs: [String]) {
syncStatusTable.resetSelectedForProcessing(articleIDs) syncStatusTable.resetSelectedForProcessing(articleIDs)
} }

View File

@ -39,6 +39,23 @@ final class SyncStatusTable: DatabaseTable {
} }
func selectPendingCount() -> Int {
var count: Int = 0
self.queue.fetchSync { (database) in
let sql = "select count(*) from syncStatus"
if let resultSet = database.executeQuery(sql, withArgumentsIn: nil) {
resultSet.next()
count = Int(resultSet.int(forColumnIndex: 0))
}
}
return count
}
func resetSelectedForProcessing(_ articleIDs: [String]) { func resetSelectedForProcessing(_ articleIDs: [String]) {
self.queue.update { database in self.queue.update { database in
let parameters = articleIDs.map { $0 as AnyObject } let parameters = articleIDs.map { $0 as AnyObject }