From db564d9cf997173408507437ac9bc29e0fa89554 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 17 Dec 2019 21:15:20 -0800 Subject: [PATCH] Remove all references to fetchArticleIDsForStatusesWithoutArticles. Use fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate instead. --- Frameworks/Account/Account.swift | 5 -- .../FeedWranglerAccountDelegate.swift | 61 +++++++++++-------- .../ReaderAPI/ReaderAPIAccountDelegate.swift | 54 +++++++++------- .../ArticlesDatabase/ArticlesDatabase.swift | 5 -- .../ArticlesDatabase/ArticlesTable.swift | 4 -- .../ArticlesDatabase/StatusesTable.swift | 4 -- 6 files changed, 66 insertions(+), 67 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 5c9153e39..4eac70446 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -689,11 +689,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, database.fetchStarredArticleIDsAsync(webFeedIDs: flattenedWebFeeds().webFeedIDs(), completion: completion) } - /// Deprecated. Use fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate instead. - public func fetchArticleIDsForStatusesWithoutArticles() throws -> Set { - return try database.fetchArticleIDsForStatusesWithoutArticles() - } - /// Fetch articleIDs for articles that we should have, but don’t. These articles are not userDeleted, and they are either (starred) or (unread and newer than the article cutoff date). public func fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(_ completion: @escaping ArticleIDsCompletionBlock) { database.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(completion) diff --git a/Frameworks/Account/FeedWrangler/FeedWranglerAccountDelegate.swift b/Frameworks/Account/FeedWrangler/FeedWranglerAccountDelegate.swift index 905fb4f44..8186e378b 100644 --- a/Frameworks/Account/FeedWrangler/FeedWranglerAccountDelegate.swift +++ b/Frameworks/Account/FeedWrangler/FeedWranglerAccountDelegate.swift @@ -165,36 +165,45 @@ final class FeedWranglerAccountDelegate: AccountDelegate { } func refreshMissingArticles(for account: Account, completion: @escaping ((Result)-> Void)) { - guard let fetchedArticleIDs = try? account.fetchArticleIDsForStatusesWithoutArticles() else { - return - } + account.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate { articleIDsResult in - os_log(.debug, log: log, "Refreshing missing articles...") - let group = DispatchGroup() - - let articleIDs = Array(fetchedArticleIDs) - let chunkedArticleIDs = articleIDs.chunked(into: 100) - - for chunk in chunkedArticleIDs { - group.enter() - self.caller.retrieveEntries(articleIDs: chunk) { result in - switch result { - case .success(let entries): - self.syncFeedItems(account, entries) { - group.leave() + func process(_ fetchedArticleIDs: Set) { + os_log(.debug, log: self.log, "Refreshing missing articles...") + let group = DispatchGroup() + + let articleIDs = Array(fetchedArticleIDs) + let chunkedArticleIDs = articleIDs.chunked(into: 100) + + for chunk in chunkedArticleIDs { + group.enter() + self.caller.retrieveEntries(articleIDs: chunk) { result in + switch result { + case .success(let entries): + self.syncFeedItems(account, entries) { + group.leave() + } + + case .failure(let error): + os_log(.error, log: self.log, "Refresh missing articles failed: %@", error.localizedDescription) + group.leave() + } } - - case .failure(let error): - os_log(.error, log: self.log, "Refresh missing articles failed: %@", error.localizedDescription) - group.leave() + } + + group.notify(queue: DispatchQueue.main) { + self.refreshProgress.completeTask() + os_log(.debug, log: self.log, "Done refreshing missing articles.") + completion(.success(())) } } - } - - group.notify(queue: DispatchQueue.main) { - self.refreshProgress.completeTask() - os_log(.debug, log: self.log, "Done refreshing missing articles.") - completion(.success(())) + + switch articleIDsResult { + case .success(let articleIDs): + process(articleIDs) + case .failure(let databaseError): + self.refreshProgress.completeTask() + completion(.failure(databaseError)) + } } } diff --git a/Frameworks/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Frameworks/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 6de5ed187..fc3c891dd 100644 --- a/Frameworks/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Frameworks/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -837,38 +837,46 @@ private extension ReaderAPIAccountDelegate { } func refreshMissingArticles(_ account: Account, completion: @escaping VoidCompletionBlock) { - guard let fetchedArticleIDs = try? account.fetchArticleIDsForStatusesWithoutArticles() else { - self.refreshProgress.completeTask() - return - } + account.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate { articleIDsResult in - os_log(.debug, log: log, "Refreshing missing articles...") - let group = DispatchGroup() + func process(_ fetchedArticleIDs: Set) { + os_log(.debug, log: self.log, "Refreshing missing articles...") + let group = DispatchGroup() - let articleIDs = Array(fetchedArticleIDs) - let chunkedArticleIDs = articleIDs.chunked(into: 100) + let articleIDs = Array(fetchedArticleIDs) + let chunkedArticleIDs = articleIDs.chunked(into: 100) - for chunk in chunkedArticleIDs { - group.enter() - self.caller.retrieveEntries(articleIDs: chunk) { result in + for chunk in chunkedArticleIDs { + group.enter() + self.caller.retrieveEntries(articleIDs: chunk) { result in - switch result { - case .success(let entries): - self.processEntries(account: account, entries: entries) { - group.leave() + switch result { + case .success(let entries): + self.processEntries(account: account, entries: entries) { + group.leave() + } + + case .failure(let error): + os_log(.error, log: self.log, "Refresh missing articles failed: %@.", error.localizedDescription) + group.leave() + } } + } - case .failure(let error): - os_log(.error, log: self.log, "Refresh missing articles failed: %@.", error.localizedDescription) - group.leave() + group.notify(queue: DispatchQueue.main) { + self.refreshProgress.completeTask() + os_log(.debug, log: self.log, "Done refreshing missing articles.") + completion() } } - } - group.notify(queue: DispatchQueue.main) { - self.refreshProgress.completeTask() - os_log(.debug, log: self.log, "Done refreshing missing articles.") - completion() + switch articleIDsResult { + case .success(let articleIDs): + process(articleIDs) + case .failure: + self.refreshProgress.completeTask() + completion() + } } } diff --git a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift index 646ad408d..c43e409bf 100644 --- a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift +++ b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift @@ -176,11 +176,6 @@ public final class ArticlesDatabase { articlesTable.fetchStarredArticleIDsAsync(webFeedIDs, completion) } - /// Deprecated. Use `fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate` instead. - public func fetchArticleIDsForStatusesWithoutArticles() throws -> Set { - return try articlesTable.fetchArticleIDsForStatusesWithoutArticles() - } - /// Fetch articleIDs for articles that we should have, but don’t. These articles are not userDeleted, and they are either (starred) or (unread and newer than the article cutoff date). public func fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(_ completion: @escaping ArticleIDsCompletionBlock) { articlesTable.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(completion) diff --git a/Frameworks/ArticlesDatabase/ArticlesTable.swift b/Frameworks/ArticlesDatabase/ArticlesTable.swift index 688a749f6..877b1b0b6 100644 --- a/Frameworks/ArticlesDatabase/ArticlesTable.swift +++ b/Frameworks/ArticlesDatabase/ArticlesTable.swift @@ -380,10 +380,6 @@ final class ArticlesTable: DatabaseTable { return try statusesTable.fetchStarredArticleIDs() } - func fetchArticleIDsForStatusesWithoutArticles() throws -> Set { - return try statusesTable.fetchArticleIDsForStatusesWithoutArticles() - } - func fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(_ completion: @escaping ArticleIDsCompletionBlock) { statusesTable.fetchArticleIDsForStatusesWithoutArticlesNewerThan(articleCutoffDate, completion) } diff --git a/Frameworks/ArticlesDatabase/StatusesTable.swift b/Frameworks/ArticlesDatabase/StatusesTable.swift index 651387094..a9e67d5eb 100644 --- a/Frameworks/ArticlesDatabase/StatusesTable.swift +++ b/Frameworks/ArticlesDatabase/StatusesTable.swift @@ -101,10 +101,6 @@ final class StatusesTable: DatabaseTable { return try fetchArticleIDs("select articleID from statuses where starred=1 and userDeleted=0;") } - func fetchArticleIDsForStatusesWithoutArticles() throws -> Set { - return try fetchArticleIDs("select articleID from statuses s where (read=0 or starred=1) and userDeleted=0 and not exists (select 1 from articles a where a.articleID = s.articleID);") - } - func fetchArticleIDsForStatusesWithoutArticlesNewerThan(_ cutoffDate: Date, _ completion: @escaping ArticleIDsCompletionBlock) { queue.runInDatabase { databaseResult in