mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-02 20:16:54 +01:00
Make SyncDatabase selectPendingCount async.
This commit is contained in:
parent
894d3909a3
commit
7a134740ec
@ -412,9 +412,9 @@ final class FeedWranglerAccountDelegate: AccountDelegate {
|
|||||||
let syncStatuses = articles.map { SyncStatus(articleID: $0.articleID, key: statusKey, flag: flag)}
|
let syncStatuses = articles.map { SyncStatus(articleID: $0.articleID, key: statusKey, flag: flag)}
|
||||||
database.insertStatuses(syncStatuses)
|
database.insertStatuses(syncStatuses)
|
||||||
|
|
||||||
if database.selectPendingCount() > 0 {
|
database.selectPendingCount { result in
|
||||||
sendArticleStatus(for: account) { _ in
|
if let count = try? result.get(), count > 0 {
|
||||||
// do it in the background
|
self.sendArticleStatus(for: account) { _ in }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,12 +525,13 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
|||||||
}
|
}
|
||||||
database.insertStatuses(syncStatuses)
|
database.insertStatuses(syncStatuses)
|
||||||
|
|
||||||
if database.selectPendingCount() > 100 {
|
database.selectPendingCount { result in
|
||||||
sendArticleStatus(for: account) { _ in }
|
if let count = try? result.get(), count > 100 {
|
||||||
|
self.sendArticleStatus(for: account) { _ in }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return account.update(articles, statusKey: statusKey, flag: flag)
|
return account.update(articles, statusKey: statusKey, flag: flag)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func accountDidInitialize(_ account: Account) {
|
func accountDidInitialize(_ account: Account) {
|
||||||
|
@ -485,8 +485,10 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
|||||||
database.insertStatuses(syncStatuses)
|
database.insertStatuses(syncStatuses)
|
||||||
os_log(.debug, log: log, "Marking %@ as %@.", articles.map { $0.title }, syncStatuses)
|
os_log(.debug, log: log, "Marking %@ as %@.", articles.map { $0.title }, syncStatuses)
|
||||||
|
|
||||||
if database.selectPendingCount() > 100 {
|
database.selectPendingCount { result in
|
||||||
sendArticleStatus(for: account) { _ in }
|
if let count = try? result.get(), count > 100 {
|
||||||
|
self.sendArticleStatus(for: account) { _ in }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return account.update(articles, statusKey: statusKey, flag: flag)
|
return account.update(articles, statusKey: statusKey, flag: flag)
|
||||||
|
@ -402,8 +402,10 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
|||||||
}
|
}
|
||||||
database.insertStatuses(syncStatuses)
|
database.insertStatuses(syncStatuses)
|
||||||
|
|
||||||
if database.selectPendingCount() > 100 {
|
database.selectPendingCount { result in
|
||||||
sendArticleStatus(for: account) { _ in }
|
if let count = try? result.get(), count > 100 {
|
||||||
|
self.sendArticleStatus(for: account) { _ in }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return account.update(articles, statusKey: statusKey, flag: flag)
|
return account.update(articles, statusKey: statusKey, flag: flag)
|
||||||
|
@ -34,8 +34,8 @@ public struct SyncDatabase {
|
|||||||
return try syncStatusTable.selectForProcessing()
|
return try syncStatusTable.selectForProcessing()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func selectPendingCount() throws -> Int {
|
public func selectPendingCount(completion: @escaping DatabaseIntCompletionBlock) {
|
||||||
return try syncStatusTable.selectPendingCount()
|
syncStatusTable.selectPendingCount(completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func resetSelectedForProcessing(_ articleIDs: [String], completion: DatabaseCompletionBlock? = nil) {
|
public func resetSelectedForProcessing(_ articleIDs: [String], completion: DatabaseCompletionBlock? = nil) {
|
||||||
|
@ -50,16 +50,15 @@ struct SyncStatusTable: DatabaseTable {
|
|||||||
return statuses != nil ? Array(statuses!) : [SyncStatus]()
|
return statuses != nil ? Array(statuses!) : [SyncStatus]()
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectPendingCount() throws -> Int {
|
func selectPendingCount(_ completion: @escaping DatabaseIntCompletionBlock) {
|
||||||
var count: Int = 0
|
queue.runInDatabase { databaseResult in
|
||||||
var error: DatabaseError?
|
var count: Int = 0
|
||||||
|
var error: DatabaseError?
|
||||||
queue.runInDatabaseSync { databaseResult in
|
|
||||||
|
|
||||||
func makeDatabaseCall(_ database: FMDatabase) {
|
func makeDatabaseCall(_ database: FMDatabase) {
|
||||||
let sql = "select count(*) from syncStatus"
|
let sql = "select count(*) from syncStatus"
|
||||||
if let resultSet = database.executeQuery(sql, withArgumentsIn: nil) {
|
if let resultSet = database.executeQuery(sql, withArgumentsIn: nil) {
|
||||||
count = numberWithCountResultSet(resultSet)
|
count = self.numberWithCountResultSet(resultSet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,12 +68,16 @@ struct SyncStatusTable: DatabaseTable {
|
|||||||
case .failure(let databaseError):
|
case .failure(let databaseError):
|
||||||
error = databaseError
|
error = databaseError
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let error = error {
|
DispatchQueue.main.async {
|
||||||
throw(error)
|
if let error = error {
|
||||||
|
completion(.failure(error))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
completion(.success(count))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return count
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetSelectedForProcessing(_ articleIDs: [String], completion: DatabaseCompletionBlock? = nil) {
|
func resetSelectedForProcessing(_ articleIDs: [String], completion: DatabaseCompletionBlock? = nil) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user