Change so that we don't join with the articles table when finding starred or unread article ids. Fixes #2915
This commit is contained in:
parent
aaf7b9b38a
commit
c35dabbc55
|
@ -731,11 +731,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||
}
|
||||
|
||||
public func fetchUnreadArticleIDs(_ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
database.fetchUnreadArticleIDsAsync(webFeedIDs: flattenedWebFeeds().webFeedIDs(), completion: completion)
|
||||
database.fetchUnreadArticleIDsAsync(completion: completion)
|
||||
}
|
||||
|
||||
public func fetchStarredArticleIDs(_ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
database.fetchStarredArticleIDsAsync(webFeedIDs: flattenedWebFeeds().webFeedIDs(), completion: completion)
|
||||
database.fetchStarredArticleIDsAsync(completion: completion)
|
||||
}
|
||||
|
||||
/// Fetch articleIDs for articles that we should have, but don’t. These articles are either (starred) or (newer than the article cutoff date).
|
||||
|
|
|
@ -222,14 +222,14 @@ public final class ArticlesDatabase {
|
|||
|
||||
// MARK: - Status
|
||||
|
||||
/// Fetch the articleIDs of unread articles in feeds specified by webFeedIDs.
|
||||
public func fetchUnreadArticleIDsAsync(webFeedIDs: Set<String>, completion: @escaping ArticleIDsCompletionBlock) {
|
||||
articlesTable.fetchUnreadArticleIDsAsync(webFeedIDs, completion)
|
||||
/// Fetch the articleIDs of unread articles.
|
||||
public func fetchUnreadArticleIDsAsync(completion: @escaping ArticleIDsCompletionBlock) {
|
||||
articlesTable.fetchUnreadArticleIDsAsync(completion)
|
||||
}
|
||||
|
||||
/// Fetch the articleIDs of starred articles in feeds specified by webFeedIDs.
|
||||
public func fetchStarredArticleIDsAsync(webFeedIDs: Set<String>, completion: @escaping ArticleIDsCompletionBlock) {
|
||||
articlesTable.fetchStarredArticleIDsAsync(webFeedIDs, completion)
|
||||
/// Fetch the articleIDs of starred articles.
|
||||
public func fetchStarredArticleIDsAsync(completion: @escaping ArticleIDsCompletionBlock) {
|
||||
articlesTable.fetchStarredArticleIDsAsync(completion)
|
||||
}
|
||||
|
||||
/// Fetch articleIDs for articles that we should have, but don’t. These articles are either (starred) or (newer than the article cutoff date).
|
||||
|
|
|
@ -418,12 +418,12 @@ final class ArticlesTable: DatabaseTable {
|
|||
|
||||
// MARK: - Statuses
|
||||
|
||||
func fetchUnreadArticleIDsAsync(_ webFeedIDs: Set<String>, _ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
fetchArticleIDsAsync(.read, false, webFeedIDs, completion)
|
||||
func fetchUnreadArticleIDsAsync(_ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
statusesTable.fetchArticleIDsAsync(.read, false, completion)
|
||||
}
|
||||
|
||||
func fetchStarredArticleIDsAsync(_ webFeedIDs: Set<String>, _ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
fetchArticleIDsAsync(.starred, true, webFeedIDs, completion)
|
||||
func fetchStarredArticleIDsAsync(_ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
statusesTable.fetchArticleIDsAsync(.starred, true, completion)
|
||||
}
|
||||
|
||||
func fetchStarredArticleIDs() throws -> Set<String> {
|
||||
|
@ -768,46 +768,6 @@ private extension ArticlesTable {
|
|||
return articlesWithResultSet(resultSet, database)
|
||||
}
|
||||
|
||||
func fetchArticleIDsAsync(_ statusKey: ArticleStatus.Key, _ value: Bool, _ webFeedIDs: Set<String>, _ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
guard !webFeedIDs.isEmpty else {
|
||||
completion(.success(Set<String>()))
|
||||
return
|
||||
}
|
||||
|
||||
queue.runInDatabase { databaseResult in
|
||||
|
||||
func makeDatabaseCalls(_ database: FMDatabase) {
|
||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))!
|
||||
var sql = "select articleID from articles natural join statuses where feedID in \(placeholders) and \(statusKey.rawValue)="
|
||||
sql += value ? "1" : "0"
|
||||
sql += ";"
|
||||
|
||||
let parameters = Array(webFeedIDs) as [Any]
|
||||
|
||||
guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else {
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(Set<String>()))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
let articleIDs = resultSet.mapToSet{ $0.string(forColumnIndex: 0) }
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(articleIDs))
|
||||
}
|
||||
}
|
||||
|
||||
switch databaseResult {
|
||||
case .success(let database):
|
||||
makeDatabaseCalls(database)
|
||||
case .failure(let databaseError):
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(databaseError))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
@ -102,6 +102,38 @@ final class StatusesTable: DatabaseTable {
|
|||
return try fetchArticleIDs("select articleID from statuses where starred=1;")
|
||||
}
|
||||
|
||||
func fetchArticleIDsAsync(_ statusKey: ArticleStatus.Key, _ value: Bool, _ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
queue.runInDatabase { databaseResult in
|
||||
|
||||
func makeDatabaseCalls(_ database: FMDatabase) {
|
||||
var sql = "select articleID from statuses where \(statusKey.rawValue)="
|
||||
sql += value ? "1" : "0"
|
||||
sql += ";"
|
||||
|
||||
guard let resultSet = database.executeQuery(sql, withArgumentsIn: nil) else {
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(Set<String>()))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
let articleIDs = resultSet.mapToSet{ $0.string(forColumnIndex: 0) }
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(articleIDs))
|
||||
}
|
||||
}
|
||||
|
||||
switch databaseResult {
|
||||
case .success(let database):
|
||||
makeDatabaseCalls(database)
|
||||
case .failure(let databaseError):
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(databaseError))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fetchArticleIDsForStatusesWithoutArticlesNewerThan(_ cutoffDate: Date, _ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
queue.runInDatabase { databaseResult in
|
||||
|
||||
|
|
Loading…
Reference in New Issue