Add methods for fetching unread count since a certain date to Database.framework.

This commit is contained in:
Brent Simmons 2017-11-19 12:44:17 -08:00
parent e681007bbe
commit 19673f5c8a
2 changed files with 27 additions and 0 deletions

View File

@ -142,6 +142,28 @@ final class ArticlesTable: DatabaseTable {
} }
} }
func fetchUnreadCount(_ feeds: Set<Feed>, _ since: Date, _ callback: @escaping (Int) -> Void) {
// Get unread count for today, for instance.
let feedIDs = feeds.feedIDs()
queue.fetch { (database) in
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))!
let sql = "select count(*) from articles natural join statuses where feedID in \(placeholders) and datePublished > ? and read=0 and userDeleted=0;"
var parameters = [Any]()
parameters += Array(feedIDs) as [Any]
parameters += [since] as [Any]
let unreadCount = self.numberWithSQLAndParameters(sql, parameters, in: database)
DispatchQueue.main.async() {
callback(unreadCount)
}
}
}
// MARK: Status // MARK: Status
func mark(_ articles: Set<Article>, _ statusKey: ArticleStatus.Key, _ flag: Bool) -> Set<ArticleStatus>? { func mark(_ articles: Set<Article>, _ statusKey: ArticleStatus.Key, _ flag: Bool) -> Set<ArticleStatus>? {

View File

@ -61,6 +61,11 @@ public final class Database {
articlesTable.fetchUnreadCounts(feeds, completion) articlesTable.fetchUnreadCounts(feeds, completion)
} }
public func fetchUnreadCount(for feeds: Set<Feed>, since: Date, callback: @escaping (Int) -> Void) {
articlesTable.fetchUnreadCount(feeds, since, callback)
}
// MARK: - Saving and Updating Articles // MARK: - Saving and Updating Articles
public func update(feed: Feed, parsedFeed: ParsedFeed, completion: @escaping UpdateArticlesWithFeedCompletionBlock) { public func update(feed: Feed, parsedFeed: ParsedFeed, completion: @escaping UpdateArticlesWithFeedCompletionBlock) {