Add folder read fetch query.
This commit is contained in:
parent
387b867d71
commit
43744ec128
|
@ -47,7 +47,7 @@ public enum FetchType {
|
|||
case starred
|
||||
case unread
|
||||
case today
|
||||
case unreadForFolder(Folder)
|
||||
case folder(Folder, Bool)
|
||||
case webFeed(WebFeed)
|
||||
case articleIDs(Set<String>)
|
||||
case search(String)
|
||||
|
@ -589,8 +589,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||
return fetchUnreadArticles()
|
||||
case .today:
|
||||
return fetchTodayArticles()
|
||||
case .unreadForFolder(let folder):
|
||||
case .folder(let folder, let readFilter):
|
||||
if readFilter {
|
||||
return fetchUnreadArticles(folder: folder)
|
||||
} else {
|
||||
return fetchArticles(folder: folder)
|
||||
}
|
||||
case .webFeed(let webFeed):
|
||||
return fetchArticles(webFeed: webFeed)
|
||||
case .articleIDs(let articleIDs):
|
||||
|
@ -610,8 +614,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||
fetchUnreadArticlesAsync(callback)
|
||||
case .today:
|
||||
fetchTodayArticlesAsync(callback)
|
||||
case .unreadForFolder(let folder):
|
||||
fetchArticlesAsync(folder: folder, callback)
|
||||
case .folder(let folder, let readFilter):
|
||||
if readFilter {
|
||||
return fetchUnreadArticlesAsync(folder: folder, callback)
|
||||
} else {
|
||||
return fetchArticlesAsync(folder: folder, callback)
|
||||
}
|
||||
case .webFeed(let webFeed):
|
||||
fetchArticlesAsync(webFeed: webFeed, callback)
|
||||
case .articleIDs(let articleIDs):
|
||||
|
@ -887,10 +895,18 @@ private extension Account {
|
|||
}
|
||||
|
||||
func fetchArticles(folder: Folder) -> Set<Article> {
|
||||
return fetchUnreadArticles(forContainer: folder)
|
||||
return fetchArticles(forContainer: folder)
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(folder: Folder, _ callback: @escaping ArticleSetBlock) {
|
||||
fetchArticlesAsync(forContainer: folder, callback)
|
||||
}
|
||||
|
||||
func fetchUnreadArticles(folder: Folder) -> Set<Article> {
|
||||
return fetchUnreadArticles(forContainer: folder)
|
||||
}
|
||||
|
||||
func fetchUnreadArticlesAsync(folder: Folder, _ callback: @escaping ArticleSetBlock) {
|
||||
fetchUnreadArticlesAsync(forContainer: folder, callback)
|
||||
}
|
||||
|
||||
|
@ -945,6 +961,21 @@ private extension Account {
|
|||
}
|
||||
|
||||
|
||||
func fetchArticles(forContainer container: Container) -> Set<Article> {
|
||||
let feeds = container.flattenedWebFeeds()
|
||||
let articles = database.fetchArticles(feeds.webFeedIDs())
|
||||
validateUnreadCountsAfterFetchingUnreadArticles(feeds, articles)
|
||||
return articles
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(forContainer container: Container, _ callback: @escaping ArticleSetBlock) {
|
||||
let webFeeds = container.flattenedWebFeeds()
|
||||
database.fetchArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articles) in
|
||||
self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles)
|
||||
callback(articles)
|
||||
}
|
||||
}
|
||||
|
||||
func fetchUnreadArticles(forContainer container: Container) -> Set<Article> {
|
||||
let feeds = container.flattenedWebFeeds()
|
||||
let articles = database.fetchUnreadArticles(feeds.webFeedIDs())
|
||||
|
|
|
@ -49,11 +49,20 @@ extension WebFeed: ArticleFetcher {
|
|||
extension Folder: ArticleFetcher {
|
||||
|
||||
public func fetchArticles() -> Set<Article> {
|
||||
return fetchUnreadArticles()
|
||||
guard let account = account else {
|
||||
assertionFailure("Expected folder.account, but got nil.")
|
||||
return Set<Article>()
|
||||
}
|
||||
return account.fetchArticles(.folder(self, false))
|
||||
}
|
||||
|
||||
public func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock) {
|
||||
fetchUnreadArticlesAsync(callback)
|
||||
guard let account = account else {
|
||||
assertionFailure("Expected folder.account, but got nil.")
|
||||
callback(Set<Article>())
|
||||
return
|
||||
}
|
||||
account.fetchArticlesAsync(.folder(self, false), callback)
|
||||
}
|
||||
|
||||
public func fetchUnreadArticles() -> Set<Article> {
|
||||
|
@ -61,7 +70,7 @@ extension Folder: ArticleFetcher {
|
|||
assertionFailure("Expected folder.account, but got nil.")
|
||||
return Set<Article>()
|
||||
}
|
||||
return account.fetchArticles(.unreadForFolder(self))
|
||||
return account.fetchArticles(.folder(self, true))
|
||||
}
|
||||
|
||||
public func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock) {
|
||||
|
@ -70,6 +79,6 @@ extension Folder: ArticleFetcher {
|
|||
callback(Set<Article>())
|
||||
return
|
||||
}
|
||||
account.fetchArticlesAsync(.unreadForFolder(self), callback)
|
||||
account.fetchArticlesAsync(.folder(self, true), callback)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,12 +48,16 @@ public final class ArticlesDatabase {
|
|||
return articlesTable.fetchArticles(webFeedID)
|
||||
}
|
||||
|
||||
public func fetchArticles(_ webFeedIDs: Set<String>) -> Set<Article> {
|
||||
return articlesTable.fetchArticles(webFeedIDs)
|
||||
}
|
||||
|
||||
public func fetchArticles(articleIDs: Set<String>) -> Set<Article> {
|
||||
return articlesTable.fetchArticles(articleIDs: articleIDs)
|
||||
}
|
||||
|
||||
public func fetchUnreadArticles(_ webFeedID: Set<String>) -> Set<Article> {
|
||||
return articlesTable.fetchUnreadArticles(webFeedID)
|
||||
public func fetchUnreadArticles(_ webFeedIDs: Set<String>) -> Set<Article> {
|
||||
return articlesTable.fetchUnreadArticles(webFeedIDs)
|
||||
}
|
||||
|
||||
public func fetchTodayArticles(_ webFeedIDs: Set<String>) -> Set<Article> {
|
||||
|
@ -78,6 +82,10 @@ public final class ArticlesDatabase {
|
|||
articlesTable.fetchArticlesAsync(webFeedID, callback)
|
||||
}
|
||||
|
||||
public func fetchArticlesAsync(_ webFeedIDs: Set<String>, _ callback: @escaping ArticleSetBlock) {
|
||||
articlesTable.fetchArticlesAsync(webFeedIDs, callback)
|
||||
}
|
||||
|
||||
public func fetchArticlesAsync(articleIDs: Set<String>, _ callback: @escaping ArticleSetBlock) {
|
||||
articlesTable.fetchArticlesAsync(articleIDs: articleIDs, callback)
|
||||
}
|
||||
|
|
|
@ -60,6 +60,25 @@ final class ArticlesTable: DatabaseTable {
|
|||
return fetchArticlesWithWhereClause(database, whereClause: "articles.feedID = ?", parameters: [webFeedID as AnyObject], withLimits: withLimits)
|
||||
}
|
||||
|
||||
func fetchArticles(_ webFeedIDs: Set<String>) -> Set<Article> {
|
||||
return fetchArticles{ self.fetchArticles(webFeedIDs, $0) }
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(_ webFeedIDs: Set<String>, _ callback: @escaping ArticleSetBlock) {
|
||||
fetchArticlesAsync({ self.fetchArticles(webFeedIDs, $0) }, callback)
|
||||
}
|
||||
|
||||
private func fetchArticles(_ webFeedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> {
|
||||
// select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and read=0
|
||||
if webFeedIDs.isEmpty {
|
||||
return Set<Article>()
|
||||
}
|
||||
let parameters = webFeedIDs.map { $0 as AnyObject }
|
||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))!
|
||||
let whereClause = "feedID in \(placeholders)"
|
||||
return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters, withLimits: true)
|
||||
}
|
||||
|
||||
// MARK: - Fetching Articles by articleID
|
||||
|
||||
func fetchArticles(articleIDs: Set<String>) -> Set<Article> {
|
||||
|
|
Loading…
Reference in New Issue