From cba900d4e4c71778b91b75b1387f31f7b3dea38d Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 25 Oct 2020 12:32:12 -0500 Subject: [PATCH] Remove synchronous sync database status insert function. --- .../CloudKit/CloudKitAccountDelegate.swift | 10 ++++----- .../CloudKitArticlesZoneDelegate.swift | 5 +++-- .../FeedWranglerAccountDelegate.swift | 10 ++++----- .../Feedbin/FeedbinAccountDelegate.swift | 10 ++++----- .../Feedly/FeedlyAccountDelegate.swift | 10 ++++----- .../NewsBlur/NewsBlurAccountDelegate.swift | 10 ++++----- .../ReaderAPI/ReaderAPIAccountDelegate.swift | 10 ++++----- .../Sources/SyncDatabase/SyncDatabase.swift | 4 ---- .../SyncDatabase/SyncStatusTable.swift | 21 ++----------------- 9 files changed, 35 insertions(+), 55 deletions(-) diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index f0f578c3d..71ea4da7a 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -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): diff --git a/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift index c22009423..53c587ce6 100644 --- a/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift @@ -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) diff --git a/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift b/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift index 7784f029b..f9f07e377 100644 --- a/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift +++ b/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift @@ -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): diff --git a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index df4a49b59..d934b0162 100644 --- a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -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): diff --git a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index b871a10f2..558b1ba5b 100644 --- a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -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): diff --git a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index d335719ad..e239a6706 100644 --- a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -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): diff --git a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index f971ef50c..871d1ffa6 100644 --- a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -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): diff --git a/SyncDatabase/Sources/SyncDatabase/SyncDatabase.swift b/SyncDatabase/Sources/SyncDatabase/SyncDatabase.swift index 9f5fd0827..93726a113 100644 --- a/SyncDatabase/Sources/SyncDatabase/SyncDatabase.swift +++ b/SyncDatabase/Sources/SyncDatabase/SyncDatabase.swift @@ -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) } diff --git a/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift b/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift index ac5a510eb..fd2043390 100644 --- a/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift +++ b/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift @@ -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) } } }