From 03fd162d3794ecf56bf220c3481f3c18b7e935d0 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 8 Dec 2019 22:17:25 -0800 Subject: [PATCH] =?UTF-8?q?Use=20datePublished=20when=20fetching=20article?= =?UTF-8?q?s=20for=20a=20feed=20for=20display=20in=20the=20UI.=20This=20de?= =?UTF-8?q?fines=20the=20window=20instead=20of=20dateArrived=20=E2=80=94?= =?UTF-8?q?=C2=A0though=20dateArrived=20is=20still=20the=20fallback=20when?= =?UTF-8?q?=20datePublished=20is=20nil.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArticlesDatabase/ArticlesTable.swift | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Frameworks/ArticlesDatabase/ArticlesTable.swift b/Frameworks/ArticlesDatabase/ArticlesTable.swift index ef98710d5..4cdf8ea31 100644 --- a/Frameworks/ArticlesDatabase/ArticlesTable.swift +++ b/Frameworks/ArticlesDatabase/ArticlesTable.swift @@ -349,9 +349,9 @@ final class ArticlesTable: DatabaseTable { let cutoffDate = articleCutoffDate queue.runInDatabase { (database) in - let sql = "select distinct feedID, count(*) from articles natural join statuses where read=0 and userDeleted=0 and (starred=1 or dateArrived>?) group by feedID;" + let sql = "select distinct feedID, count(*) from articles natural join statuses where read=0 and userDeleted=0 and (starred=1 or (datePublished > ? or (datePublished is null and dateArrived > ?))) group by feedID;" - guard let resultSet = database.executeQuery(sql, withArgumentsIn: [cutoffDate]) else { + guard let resultSet = database.executeQuery(sql, withArgumentsIn: [cutoffDate, cutoffDate]) else { DispatchQueue.main.async { completion(UnreadCountDictionary()) } @@ -586,8 +586,8 @@ private extension ArticlesTable { // * Must be either 1) starred or 2) dateArrived must be newer than cutoff date. if withLimits { - let sql = "select * from articles natural join statuses where \(whereClause) and userDeleted=0 and (starred=1 or dateArrived>?);" - return articlesWithSQL(sql, parameters + [articleCutoffDate as AnyObject], database) + let sql = "select * from articles natural join statuses where \(whereClause) and userDeleted=0 and (starred=1 or (datePublished > ? or (datePublished is null and dateArrived > ?)));" + return articlesWithSQL(sql, parameters + [articleCutoffDate as AnyObject] + [articleCutoffDate as AnyObject], database) } else { let sql = "select * from articles natural join statuses where \(whereClause);" @@ -601,8 +601,8 @@ private extension ArticlesTable { // * Must not be deleted. // * Must be either 1) starred or 2) dateArrived must be newer than cutoff date. - let sql = "select count(*) from articles natural join statuses where feedID=? and read=0 and userDeleted=0 and (starred=1 or dateArrived>?);" - return numberWithSQLAndParameters(sql, [webFeedID, articleCutoffDate], in: database) + let sql = "select count(*) from articles natural join statuses where feedID=? and read=0 and userDeleted=0 and (starred=1 or (datePublished > ? or (datePublished is null and dateArrived > ?)));" + return numberWithSQLAndParameters(sql, [webFeedID, articleCutoffDate, articleCutoffDate], in: database) } func fetchArticlesMatching(_ searchString: String, _ database: FMDatabase) -> Set
{ @@ -786,20 +786,23 @@ private extension ArticlesTable { } } - func statusIndicatesArticleIsIgnorable(_ status: ArticleStatus) -> Bool { + func articleIsIgnorable(_ article: Article) -> Bool { // Ignorable articles: either userDeleted==1 or (not starred and arrival date > 4 months). - if status.userDeleted { + if article.status.userDeleted { return true } - if status.starred { + if article.status.starred { return false } - return status.dateArrived < maximumArticleCutoffDate + if let datePublished = article.datePublished { + return datePublished < maximumArticleCutoffDate + } + return article.status.dateArrived < maximumArticleCutoffDate } func filterIncomingArticles(_ articles: Set
) -> Set
{ // Drop Articles that we can ignore. - return Set(articles.filter{ !statusIndicatesArticleIsIgnorable($0.status) }) + return Set(articles.filter{ !articleIsIgnorable($0) }) } func removeArticles(_ articleIDs: Set, _ database: FMDatabase) {