mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-22 07:13:58 +01:00
Remove synchronous sync database status insert function.
This commit is contained in:
parent
45f5776b7e
commit
cba900d4e4
@ -407,11 +407,11 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
||||
return SyncStatus(articleID: article.articleID, key: SyncStatus.Key(statusKey), flag: flag)
|
||||
}
|
||||
|
||||
try? self.database.insertStatuses(syncStatuses)
|
||||
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account, showProgress: false) { _ in }
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account, showProgress: false) { _ in }
|
||||
}
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
|
@ -148,8 +148,9 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
return
|
||||
}
|
||||
let syncStatuses = deletes.map { SyncStatus(articleID: $0.articleID, key: .deleted, flag: true) }
|
||||
try? self.database.insertStatuses(syncStatuses)
|
||||
group.leave()
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
group.leave()
|
||||
}
|
||||
case .failure(let databaseError):
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Error occurred while storing articles: %@", databaseError.localizedDescription)
|
||||
|
@ -443,11 +443,11 @@ final class FeedWranglerAccountDelegate: AccountDelegate {
|
||||
return SyncStatus(articleID: article.articleID, key: SyncStatus.Key(statusKey), flag: flag)
|
||||
}
|
||||
|
||||
try? self.database.insertStatuses(syncStatuses)
|
||||
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
|
@ -542,11 +542,11 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
return SyncStatus(articleID: article.articleID, key: SyncStatus.Key(statusKey), flag: flag)
|
||||
}
|
||||
|
||||
try? self.database.insertStatuses(syncStatuses)
|
||||
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
|
@ -495,11 +495,11 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
return SyncStatus(articleID: article.articleID, key: SyncStatus.Key(statusKey), flag: flag)
|
||||
}
|
||||
|
||||
try? self.database.insertStatuses(syncStatuses)
|
||||
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
|
@ -581,11 +581,11 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
return SyncStatus(articleID: article.articleID, key: SyncStatus.Key(statusKey), flag: flag)
|
||||
}
|
||||
|
||||
try? self.database.insertStatuses(syncStatuses)
|
||||
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
|
@ -472,11 +472,11 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
return SyncStatus(articleID: article.articleID, key: SyncStatus.Key(statusKey), flag: flag)
|
||||
}
|
||||
|
||||
try? self.database.insertStatuses(syncStatuses)
|
||||
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
self.database.selectPendingCount { result in
|
||||
if let count = try? result.get(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
|
@ -32,10 +32,6 @@ public struct SyncDatabase {
|
||||
|
||||
// MARK: - API
|
||||
|
||||
public func insertStatuses(_ statuses: [SyncStatus]) throws {
|
||||
try syncStatusTable.insertStatuses(statuses)
|
||||
}
|
||||
|
||||
public func insertStatuses(_ statuses: [SyncStatus], completion: @escaping DatabaseCompletionBlock) {
|
||||
syncStatusTable.insertStatuses(statuses, completion: completion)
|
||||
}
|
||||
|
@ -153,23 +153,6 @@ struct SyncStatusTable: DatabaseTable {
|
||||
}
|
||||
}
|
||||
|
||||
func insertStatuses(_ statuses: [SyncStatus]) throws {
|
||||
var error: DatabaseError?
|
||||
queue.runInTransactionSync { databaseResult in
|
||||
switch databaseResult {
|
||||
case .success(let database):
|
||||
let statusArray = statuses.map { $0.databaseDictionary() }
|
||||
self.insertRows(statusArray, insertType: .orReplace, in: database)
|
||||
case .failure(let databaseError):
|
||||
error = databaseError
|
||||
}
|
||||
}
|
||||
|
||||
if let error = error {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
func insertStatuses(_ statuses: [SyncStatus], completion: @escaping DatabaseCompletionBlock) {
|
||||
queue.runInTransaction { databaseResult in
|
||||
|
||||
@ -181,9 +164,9 @@ struct SyncStatusTable: DatabaseTable {
|
||||
switch databaseResult {
|
||||
case .success(let database):
|
||||
makeDatabaseCall(database)
|
||||
completion(nil)
|
||||
callCompletion(completion, nil)
|
||||
case .failure(let databaseError):
|
||||
completion(databaseError)
|
||||
callCompletion(completion, databaseError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user