Remove synchronous sync database status insert function.

This commit is contained in:
Maurice Parker 2020-10-25 12:32:12 -05:00
parent 45f5776b7e
commit cba900d4e4
9 changed files with 35 additions and 55 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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)
}

View File

@ -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)
}
}
}