Remove all references to fetchArticleIDsForStatusesWithoutArticles. Use fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate instead.

This commit is contained in:
Brent Simmons 2019-12-17 21:15:20 -08:00
parent 6d499c8848
commit db564d9cf9
6 changed files with 66 additions and 67 deletions

View File

@ -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<String> {
return try database.fetchArticleIDsForStatusesWithoutArticles()
}
/// Fetch articleIDs for articles that we should have, but dont. 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)

View File

@ -165,36 +165,45 @@ final class FeedWranglerAccountDelegate: AccountDelegate {
}
func refreshMissingArticles(for account: Account, completion: @escaping ((Result<Void, Error>)-> 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<String>) {
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))
}
}
}

View File

@ -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<String>) {
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()
}
}
}

View File

@ -176,11 +176,6 @@ public final class ArticlesDatabase {
articlesTable.fetchStarredArticleIDsAsync(webFeedIDs, completion)
}
/// Deprecated. Use `fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate` instead.
public func fetchArticleIDsForStatusesWithoutArticles() throws -> Set<String> {
return try articlesTable.fetchArticleIDsForStatusesWithoutArticles()
}
/// Fetch articleIDs for articles that we should have, but dont. 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)

View File

@ -380,10 +380,6 @@ final class ArticlesTable: DatabaseTable {
return try statusesTable.fetchStarredArticleIDs()
}
func fetchArticleIDsForStatusesWithoutArticles() throws -> Set<String> {
return try statusesTable.fetchArticleIDsForStatusesWithoutArticles()
}
func fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(_ completion: @escaping ArticleIDsCompletionBlock) {
statusesTable.fetchArticleIDsForStatusesWithoutArticlesNewerThan(articleCutoffDate, completion)
}

View File

@ -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<String> {
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