Delete completion-based selectPendingReadStatusArticleIDs method.
This commit is contained in:
parent
951349ffc5
commit
8b84ed6e2f
@ -415,13 +415,11 @@ enum CloudKitAccountDelegateError: LocalizedError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.database.insertStatuses(syncStatuses) { _ in
|
self.database.insertStatuses(syncStatuses) { _ in
|
||||||
self.database.selectPendingCount { result in
|
Task { @MainActor in
|
||||||
MainActor.assumeIsolated {
|
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||||
if let count = try? result.get(), count > 100 {
|
self.sendArticleStatus(for: account, showProgress: false) { _ in }
|
||||||
self.sendArticleStatus(for: account, showProgress: false) { _ in }
|
|
||||||
}
|
|
||||||
completion(.success(()))
|
|
||||||
}
|
}
|
||||||
|
completion(.success(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
|
@ -34,31 +34,23 @@ class CloudKitArticlesZoneDelegate: CloudKitZoneDelegate {
|
|||||||
|
|
||||||
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result<Void, Error>) -> Void) {
|
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
|
|
||||||
database.selectPendingReadStatusArticleIDs() { result in
|
Task { @MainActor in
|
||||||
switch result {
|
do {
|
||||||
case .success(let pendingReadStatusArticleIDs):
|
|
||||||
|
|
||||||
Task { @MainActor in
|
let pendingReadStatusArticleIDs = (try await self.database.selectPendingReadStatusArticleIDs()) ?? Set<String>()
|
||||||
|
let pendingStarredStatusArticleIDs = (try await self.database.selectPendingStarredStatusArticleIDs()) ?? Set<String>()
|
||||||
|
|
||||||
do {
|
self.delete(recordKeys: deleted, pendingStarredStatusArticleIDs: pendingStarredStatusArticleIDs) {
|
||||||
|
Task { @MainActor in
|
||||||
let pendingStarredStatusArticleIDs = (try await self.database.selectPendingStarredStatusArticleIDs()) ?? Set<String>()
|
self.update(records: changed,
|
||||||
self.delete(recordKeys: deleted, pendingStarredStatusArticleIDs: pendingStarredStatusArticleIDs) {
|
pendingReadStatusArticleIDs: pendingReadStatusArticleIDs,
|
||||||
Task { @MainActor in
|
pendingStarredStatusArticleIDs: pendingStarredStatusArticleIDs,
|
||||||
self.update(records: changed,
|
completion: completion)
|
||||||
pendingReadStatusArticleIDs: pendingReadStatusArticleIDs,
|
|
||||||
pendingStarredStatusArticleIDs: pendingStarredStatusArticleIDs,
|
|
||||||
completion: completion)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} 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)
|
} catch {
|
||||||
|
os_log(.error, log: self.log, "Error occurred getting pending status records: %@", error.localizedDescription)
|
||||||
completion(.failure(CloudKitZoneError.unknown))
|
completion(.failure(CloudKitZoneError.unknown))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,28 +46,24 @@ class CloudKitSendStatusOperation: MainThreadOperation {
|
|||||||
|
|
||||||
if showProgress {
|
if showProgress {
|
||||||
|
|
||||||
database.selectPendingCount() { result in
|
Task { @MainActor in
|
||||||
MainActor.assumeIsolated {
|
|
||||||
switch result {
|
do {
|
||||||
case .success(let count):
|
let count = (try await self.database.selectPendingCount()) ?? 0
|
||||||
let ticks = count / self.blockSize
|
let ticks = count / self.blockSize
|
||||||
self.refreshProgress?.addToNumberOfTasksAndRemaining(ticks)
|
self.refreshProgress?.addToNumberOfTasksAndRemaining(ticks)
|
||||||
self.selectForProcessing()
|
self.selectForProcessing()
|
||||||
case .failure(let databaseError):
|
} catch {
|
||||||
os_log(.error, log: self.log, "Send status count pending error: %@.", databaseError.localizedDescription)
|
os_log(.error, log: self.log, "Send status count pending error: %@.", error.localizedDescription)
|
||||||
self.operationDelegate?.cancelOperation(self)
|
self.operationDelegate?.cancelOperation(self)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
selectForProcessing()
|
selectForProcessing()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension CloudKitSendStatusOperation {
|
private extension CloudKitSendStatusOperation {
|
||||||
|
@ -565,13 +565,12 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.database.insertStatuses(syncStatuses) { _ in
|
self.database.insertStatuses(syncStatuses) { _ in
|
||||||
self.database.selectPendingCount { result in
|
|
||||||
MainActor.assumeIsolated {
|
Task { @MainActor in
|
||||||
if let count = try? result.get(), count > 100 {
|
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||||
self.sendArticleStatus(for: account) { _ in }
|
self.sendArticleStatus(for: account) { _ in }
|
||||||
}
|
|
||||||
completion(.success(()))
|
|
||||||
}
|
}
|
||||||
|
completion(.success(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
@ -1304,9 +1303,10 @@ private extension FeedbinAccountDelegate {
|
|||||||
return
|
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>) {
|
@MainActor func process(_ pendingArticleIDs: Set<String>) {
|
||||||
|
|
||||||
@ -1340,18 +1340,14 @@ private extension FeedbinAccountDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch result {
|
process(pendingArticleIDs)
|
||||||
case .success(let pendingArticleIDs):
|
|
||||||
process(pendingArticleIDs)
|
} catch {
|
||||||
case .failure(let error):
|
os_log(.error, log: self.log, "Sync Article Read Status failed: %@.", error.localizedDescription)
|
||||||
os_log(.error, log: self.log, "Sync Article Read Status failed: %@.", error.localizedDescription)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncArticleStarredState(account: Account, articleIDs: [Int]?, completion: @escaping (() -> Void)) {
|
func syncArticleStarredState(account: Account, articleIDs: [Int]?, completion: @escaping (() -> Void)) {
|
||||||
|
@ -515,13 +515,12 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.database.insertStatuses(syncStatuses) { _ in
|
self.database.insertStatuses(syncStatuses) { _ in
|
||||||
self.database.selectPendingCount { result in
|
|
||||||
MainActor.assumeIsolated {
|
Task { @MainActor in
|
||||||
if let count = try? result.get(), count > 100 {
|
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||||
self.sendArticleStatus(for: account) { _ in }
|
self.sendArticleStatus(for: account) { _ in }
|
||||||
}
|
|
||||||
completion(.success(()))
|
|
||||||
}
|
}
|
||||||
|
completion(.success(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
|
@ -324,13 +324,16 @@ extension NewsBlurAccountDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func syncStoryReadState(account: Account, hashes: [NewsBlurStoryHash]?, completion: @escaping (() -> Void)) {
|
func syncStoryReadState(account: Account, hashes: [NewsBlurStoryHash]?, completion: @escaping (() -> Void)) {
|
||||||
|
|
||||||
guard let hashes = hashes else {
|
guard let hashes = hashes else {
|
||||||
completion()
|
completion()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
database.selectPendingReadStatusArticleIDs() { result in
|
Task { @MainActor in
|
||||||
MainActor.assumeIsolated {
|
do {
|
||||||
|
let pendingArticleIDs = (try await self.database.selectPendingReadStatusArticleIDs()) ?? Set<String>()
|
||||||
|
|
||||||
@MainActor func process(_ pendingStoryHashes: Set<String>) {
|
@MainActor func process(_ pendingStoryHashes: Set<String>) {
|
||||||
|
|
||||||
let newsBlurUnreadStoryHashes = Set(hashes.map { $0.hash } )
|
let newsBlurUnreadStoryHashes = Set(hashes.map { $0.hash } )
|
||||||
@ -365,12 +368,9 @@ extension NewsBlurAccountDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch result {
|
process(pendingArticleIDs)
|
||||||
case .success(let pendingArticleIDs):
|
} catch {
|
||||||
process(pendingArticleIDs)
|
os_log(.error, log: self.log, "Sync Story Read Status failed: %@.", error.localizedDescription)
|
||||||
case .failure(let error):
|
|
||||||
os_log(.error, log: self.log, "Sync Story Read Status failed: %@.", error.localizedDescription)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -595,13 +595,12 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.database.insertStatuses(syncStatuses) { _ in
|
self.database.insertStatuses(syncStatuses) { _ in
|
||||||
self.database.selectPendingCount { result in
|
|
||||||
MainActor.assumeIsolated {
|
Task { @MainActor in
|
||||||
if let count = try? result.get(), count > 100 {
|
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||||
self.sendArticleStatus(for: account) { _ in }
|
self.sendArticleStatus(for: account) { _ in }
|
||||||
}
|
|
||||||
completion(.success(()))
|
|
||||||
}
|
}
|
||||||
|
completion(.success(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
|
@ -621,13 +621,12 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.database.insertStatuses(syncStatuses) { _ in
|
self.database.insertStatuses(syncStatuses) { _ in
|
||||||
self.database.selectPendingCount { result in
|
|
||||||
MainActor.assumeIsolated {
|
Task { @MainActor in
|
||||||
if let count = try? result.get(), count > 100 {
|
if let count = try? await self.database.selectPendingCount(), count > 100 {
|
||||||
self.sendArticleStatus(for: account) { _ in }
|
self.sendArticleStatus(for: account) { _ in }
|
||||||
}
|
|
||||||
completion(.success(()))
|
|
||||||
}
|
}
|
||||||
|
completion(.success(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
@ -1108,9 +1107,11 @@ private extension ReaderAPIAccountDelegate {
|
|||||||
return
|
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>) {
|
@MainActor func process(_ pendingArticleIDs: Set<String>) {
|
||||||
let updatableReaderUnreadArticleIDs = Set(articleIDs).subtracting(pendingArticleIDs)
|
let updatableReaderUnreadArticleIDs = Set(articleIDs).subtracting(pendingArticleIDs)
|
||||||
|
|
||||||
@ -1144,15 +1145,12 @@ private extension ReaderAPIAccountDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch result {
|
process(pendingArticleIDs)
|
||||||
case .success(let pendingArticleIDs):
|
|
||||||
process(pendingArticleIDs)
|
} catch {
|
||||||
case .failure(let error):
|
os_log(.error, log: self.log, "Sync Article Read Status failed: %@.", error.localizedDescription)
|
||||||
os_log(.error, log: self.log, "Sync Article Read Status failed: %@.", error.localizedDescription)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncArticleStarredState(account: Account, articleIDs: [String]?, completion: @escaping (() -> Void)) {
|
func syncArticleStarredState(account: Account, articleIDs: [String]?, completion: @escaping (() -> Void)) {
|
||||||
|
@ -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 {
|
private extension SyncDatabase {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user