Delete completion-based insertStatuses function.
This commit is contained in:
parent
8b84ed6e2f
commit
c50ac0c84b
@ -414,13 +414,12 @@ enum CloudKitAccountDelegateError: LocalizedError {
|
||||
return SyncStatus(articleID: article.articleID, key: SyncStatus.Key(statusKey), flag: flag)
|
||||
}
|
||||
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
Task { @MainActor in
|
||||
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||
self.sendArticleStatus(for: account, showProgress: false) { _ in }
|
||||
}
|
||||
completion(.success(()))
|
||||
Task { @MainActor in
|
||||
try? await self.database.insertStatuses(syncStatuses)
|
||||
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||
self.sendArticleStatus(for: account, showProgress: false) { _ in }
|
||||
}
|
||||
completion(.success(()))
|
||||
}
|
||||
case .failure(let error):
|
||||
completion(.failure(error))
|
||||
@ -769,7 +768,10 @@ private extension CloudKitAccountDelegate {
|
||||
let syncStatuses = articles.map { article in
|
||||
return SyncStatus(articleID: article.articleID, key: statusKey, flag: flag)
|
||||
}
|
||||
database.insertStatuses(syncStatuses) { _ in
|
||||
|
||||
Task { @MainActor in
|
||||
|
||||
try? await self.database.insertStatuses(syncStatuses)
|
||||
completion()
|
||||
}
|
||||
}
|
||||
|
@ -145,24 +145,23 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
for (feedID, parsedItems) in feedIDsAndItems {
|
||||
group.enter()
|
||||
self.account?.update(feedID, with: parsedItems, deleteOlder: false) { result in
|
||||
MainActor.assumeIsolated {
|
||||
Task { @MainActor in
|
||||
switch result {
|
||||
case .success(let articleChanges):
|
||||
guard let deletes = articleChanges.deletedArticles, !deletes.isEmpty else {
|
||||
group.leave()
|
||||
return
|
||||
}
|
||||
|
||||
let syncStatuses = deletes.map { SyncStatus(articleID: $0.articleID, key: .deleted, flag: true) }
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
group.leave()
|
||||
}
|
||||
try? await self.database.insertStatuses(syncStatuses)
|
||||
group.leave()
|
||||
case .failure(let databaseError):
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Error occurred while storing articles: %@", databaseError.localizedDescription)
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -563,16 +563,16 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
let syncStatuses = articles.map { article in
|
||||
return SyncStatus(articleID: article.articleID, key: SyncStatus.Key(statusKey), flag: flag)
|
||||
}
|
||||
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
|
||||
Task { @MainActor in
|
||||
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
completion(.success(()))
|
||||
|
||||
Task { @MainActor in
|
||||
try? await self.database.insertStatuses(syncStatuses)
|
||||
|
||||
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
case .failure(let error):
|
||||
completion(.failure(error))
|
||||
}
|
||||
|
@ -514,14 +514,14 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
return SyncStatus(articleID: article.articleID, key: SyncStatus.Key(statusKey), flag: flag)
|
||||
}
|
||||
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
Task { @MainActor in
|
||||
|
||||
Task { @MainActor in
|
||||
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
completion(.success(()))
|
||||
try? await self.database.insertStatuses(syncStatuses)
|
||||
|
||||
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
completion(.success(()))
|
||||
}
|
||||
case .failure(let error):
|
||||
completion(.failure(error))
|
||||
|
@ -594,14 +594,14 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
return SyncStatus(articleID: article.articleID, key: SyncStatus.Key(statusKey), flag: flag)
|
||||
}
|
||||
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
Task { @MainActor in
|
||||
|
||||
Task { @MainActor in
|
||||
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
completion(.success(()))
|
||||
try? await self.database.insertStatuses(syncStatuses)
|
||||
|
||||
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
completion(.success(()))
|
||||
}
|
||||
case .failure(let error):
|
||||
completion(.failure(error))
|
||||
|
@ -619,22 +619,24 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
let syncStatuses = articles.map { article in
|
||||
return SyncStatus(articleID: article.articleID, key: SyncStatus.Key(statusKey), flag: flag)
|
||||
}
|
||||
|
||||
self.database.insertStatuses(syncStatuses) { _ in
|
||||
|
||||
Task { @MainActor in
|
||||
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
completion(.success(()))
|
||||
|
||||
Task { @MainActor in
|
||||
|
||||
try? await self.database.insertStatuses(syncStatuses)
|
||||
|
||||
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||
self.sendArticleStatus(for: account) { _ in }
|
||||
}
|
||||
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
case .failure(let error):
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func accountDidInitialize(_ account: Account) {
|
||||
credentials = try? account.retrieveCredentials(type: .readerAPIKey)
|
||||
}
|
||||
|
@ -122,18 +122,6 @@ public typealias SyncStatusArticleIDsCompletionBlock = @Sendable (SyncStatusArti
|
||||
|
||||
public extension SyncDatabase {
|
||||
|
||||
nonisolated func insertStatuses(_ statuses: [SyncStatus], completion: @escaping DatabaseCompletionBlock) {
|
||||
|
||||
Task { @MainActor in
|
||||
do {
|
||||
try await self.insertStatuses(statuses)
|
||||
completion(nil)
|
||||
} catch {
|
||||
completion(DatabaseError.suspended)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated func selectForProcessing(limit: Int? = nil, completion: @escaping SyncStatusesCompletionBlock) {
|
||||
|
||||
Task { @MainActor in
|
||||
|
Loading…
x
Reference in New Issue
Block a user