Created fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate — this gets articleIDs of articles we care about. They’re not deleted. They’re either (starred) or (unread and newer than cutoffDate). Also: it’s async. Use this instead of fetchArticleIDsForStatusesWithoutArticles, which is deprecated.

This commit is contained in:
Brent Simmons
2019-12-17 13:28:48 -08:00
parent 7192a6893e
commit 948d366a4e
3 changed files with 45 additions and 2 deletions

View File

@@ -104,6 +104,39 @@ final class StatusesTable: DatabaseTable {
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
var error: DatabaseError?
var articleIDs = Set<String>()
func makeDatabaseCall(_ database: FMDatabase) {
let sql = "select articleID from statuses s where ((starred=1) || (read=0 and dateArrived > ?)) and userDeleted=0 and not exists (select 1 from articles a where a.articleID = s.articleID);"
if let resultSet = database.executeQuery(sql, withArgumentsIn: [cutoffDate]) {
articleIDs = resultSet.mapToSet(self.articleIDWithRow)
}
}
switch databaseResult {
case .success(let database):
makeDatabaseCall(database)
case .failure(let databaseError):
error = databaseError
}
if let error = error {
DispatchQueue.main.async {
completion(.failure(error))
}
}
else {
DispatchQueue.main.async {
completion(.success(articleIDs))
}
}
}
}
func fetchArticleIDs(_ sql: String) throws -> Set<String> {
var error: DatabaseError?