Delete completion-based selectPendingReadStatusArticleIDs method.

This commit is contained in:
Brent Simmons 2024-03-25 22:07:21 -07:00
parent 951349ffc5
commit 8b84ed6e2f
9 changed files with 87 additions and 140 deletions

View File

@ -415,15 +415,13 @@ enum CloudKitAccountDelegateError: LocalizedError {
}
self.database.insertStatuses(syncStatuses) { _ in
self.database.selectPendingCount { result in
MainActor.assumeIsolated {
if let count = try? result.get(), count > 100 {
Task { @MainActor in
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))
}

View File

@ -34,15 +34,12 @@ class CloudKitArticlesZoneDelegate: CloudKitZoneDelegate {
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result<Void, Error>) -> Void) {
database.selectPendingReadStatusArticleIDs() { result in
switch result {
case .success(let pendingReadStatusArticleIDs):
Task { @MainActor in
do {
let pendingReadStatusArticleIDs = (try await self.database.selectPendingReadStatusArticleIDs()) ?? Set<String>()
let pendingStarredStatusArticleIDs = (try await self.database.selectPendingStarredStatusArticleIDs()) ?? Set<String>()
self.delete(recordKeys: deleted, pendingStarredStatusArticleIDs: pendingStarredStatusArticleIDs) {
Task { @MainActor in
self.update(records: changed,
@ -53,12 +50,7 @@ class CloudKitArticlesZoneDelegate: CloudKitZoneDelegate {
}
} catch {
os_log(.error, log: self.log, "Error occurred getting pending starred records: %@", error.localizedDescription)
completion(.failure(CloudKitZoneError.unknown))
}
}
case .failure(let error):
os_log(.error, log: self.log, "Error occurred getting pending read status records: %@", error.localizedDescription)
os_log(.error, log: self.log, "Error occurred getting pending status records: %@", error.localizedDescription)
completion(.failure(CloudKitZoneError.unknown))
}
}

View File

@ -46,28 +46,24 @@ class CloudKitSendStatusOperation: MainThreadOperation {
if showProgress {
database.selectPendingCount() { result in
MainActor.assumeIsolated {
switch result {
case .success(let count):
Task { @MainActor in
do {
let count = (try await self.database.selectPendingCount()) ?? 0
let ticks = count / self.blockSize
self.refreshProgress?.addToNumberOfTasksAndRemaining(ticks)
self.selectForProcessing()
case .failure(let databaseError):
os_log(.error, log: self.log, "Send status count pending error: %@.", databaseError.localizedDescription)
} catch {
os_log(.error, log: self.log, "Send status count pending error: %@.", error.localizedDescription)
self.operationDelegate?.cancelOperation(self)
}
}
}
} else {
selectForProcessing()
}
}
}
private extension CloudKitSendStatusOperation {

View File

@ -565,15 +565,14 @@ final class FeedbinAccountDelegate: AccountDelegate {
}
self.database.insertStatuses(syncStatuses) { _ in
self.database.selectPendingCount { result in
MainActor.assumeIsolated {
if let count = try? result.get(), count > 100 {
Task { @MainActor in
if let count = try? await self.database.selectPendingCount(), count > 100 {
self.sendArticleStatus(for: account) { _ in }
}
completion(.success(()))
}
}
}
case .failure(let error):
completion(.failure(error))
}
@ -1304,9 +1303,10 @@ private extension FeedbinAccountDelegate {
return
}
database.selectPendingReadStatusArticleIDs() { result in
Task { @MainActor in
do {
MainActor.assumeIsolated {
let pendingArticleIDs = (try await self.database.selectPendingReadStatusArticleIDs()) ?? Set<String>()
@MainActor func process(_ pendingArticleIDs: Set<String>) {
@ -1340,20 +1340,16 @@ private extension FeedbinAccountDelegate {
}
}
}
}
switch result {
case .success(let pendingArticleIDs):
process(pendingArticleIDs)
case .failure(let error):
} catch {
os_log(.error, log: self.log, "Sync Article Read Status failed: %@.", error.localizedDescription)
}
}
}
}
func syncArticleStarredState(account: Account, articleIDs: [Int]?, completion: @escaping (() -> Void)) {
guard let articleIDs = articleIDs else {
completion()

View File

@ -515,15 +515,14 @@ final class FeedlyAccountDelegate: AccountDelegate {
}
self.database.insertStatuses(syncStatuses) { _ in
self.database.selectPendingCount { result in
MainActor.assumeIsolated {
if let count = try? result.get(), count > 100 {
Task { @MainActor in
if let count = try? await self.database.selectPendingCount(), count > 100 {
self.sendArticleStatus(for: account) { _ in }
}
completion(.success(()))
}
}
}
case .failure(let error):
completion(.failure(error))
}

View File

@ -324,13 +324,16 @@ extension NewsBlurAccountDelegate {
}
func syncStoryReadState(account: Account, hashes: [NewsBlurStoryHash]?, completion: @escaping (() -> Void)) {
guard let hashes = hashes else {
completion()
return
}
database.selectPendingReadStatusArticleIDs() { result in
MainActor.assumeIsolated {
Task { @MainActor in
do {
let pendingArticleIDs = (try await self.database.selectPendingReadStatusArticleIDs()) ?? Set<String>()
@MainActor func process(_ pendingStoryHashes: Set<String>) {
let newsBlurUnreadStoryHashes = Set(hashes.map { $0.hash } )
@ -365,15 +368,12 @@ extension NewsBlurAccountDelegate {
}
}
switch result {
case .success(let pendingArticleIDs):
process(pendingArticleIDs)
case .failure(let error):
} catch {
os_log(.error, log: self.log, "Sync Story Read Status failed: %@.", error.localizedDescription)
}
}
}
}
func syncStoryStarredState(account: Account, hashes: [NewsBlurStoryHash]?, completion: @escaping (() -> Void)) {
guard let hashes = hashes else {

View File

@ -595,15 +595,14 @@ final class NewsBlurAccountDelegate: AccountDelegate {
}
self.database.insertStatuses(syncStatuses) { _ in
self.database.selectPendingCount { result in
MainActor.assumeIsolated {
if let count = try? result.get(), count > 100 {
Task { @MainActor in
if let count = try? await self.database.selectPendingCount(), count > 100 {
self.sendArticleStatus(for: account) { _ in }
}
completion(.success(()))
}
}
}
case .failure(let error):
completion(.failure(error))
}

View File

@ -621,15 +621,14 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
}
self.database.insertStatuses(syncStatuses) { _ in
self.database.selectPendingCount { result in
MainActor.assumeIsolated {
if let count = try? result.get(), count > 100 {
Task { @MainActor in
if let count = try? await self.database.selectPendingCount(), count > 100 {
self.sendArticleStatus(for: account) { _ in }
}
completion(.success(()))
}
}
}
case .failure(let error):
completion(.failure(error))
}
@ -1108,9 +1107,11 @@ private extension ReaderAPIAccountDelegate {
return
}
database.selectPendingReadStatusArticleIDs() { result in
Task { @MainActor in
do {
let pendingArticleIDs = (try await self.database.selectPendingReadStatusArticleIDs()) ?? Set<String>()
MainActor.assumeIsolated {
@MainActor func process(_ pendingArticleIDs: Set<String>) {
let updatableReaderUnreadArticleIDs = Set(articleIDs).subtracting(pendingArticleIDs)
@ -1144,17 +1145,14 @@ private extension ReaderAPIAccountDelegate {
}
}
switch result {
case .success(let pendingArticleIDs):
process(pendingArticleIDs)
case .failure(let error):
} catch {
os_log(.error, log: self.log, "Sync Article Read Status failed: %@.", error.localizedDescription)
}
}
}
}
func syncArticleStarredState(account: Account, articleIDs: [String]?, completion: @escaping (() -> Void)) {
guard let articleIDs = articleIDs else {
completion()

View File

@ -148,37 +148,6 @@ public extension SyncDatabase {
}
}
}
nonisolated func selectPendingCount(completion: @escaping DatabaseIntCompletionBlock) {
Task { @MainActor in
do {
if let count = try await self.selectPendingCount() {
completion(.success(count))
} else {
completion(.success(0))
}
} catch {
completion(.failure(DatabaseError.suspended))
}
}
}
nonisolated func selectPendingReadStatusArticleIDs(completion: @escaping SyncStatusArticleIDsCompletionBlock) {
Task { @MainActor in
do {
if let articleIDs = try await self.selectPendingReadStatusArticleIDs() {
completion(.success(articleIDs))
} else {
completion(.success(Set<String>()))
}
} catch {
completion(.failure(DatabaseError.suspended))
}
}
}
}
private extension SyncDatabase {