From 47f3e863b6eea4002724bc564974b1dfe5d94d1b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 8 Jan 2020 22:07:03 -0800 Subject: [PATCH] Delete articles older than the 90-day window. --- .../ArticlesDatabase/ArticlesDatabase.swift | 1 + .../ArticlesDatabase/ArticlesTable.swift | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift index c43e409bf..de2e9e286 100644 --- a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift +++ b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift @@ -216,6 +216,7 @@ public final class ArticlesDatabase { /// Calls the various clean-up functions. public func cleanupDatabaseAtStartup(subscribedToWebFeedIDs: Set) { + articlesTable.deleteOldArticles() articlesTable.deleteArticlesNotInSubscribedToFeedIDs(subscribedToWebFeedIDs) } } diff --git a/Frameworks/ArticlesDatabase/ArticlesTable.swift b/Frameworks/ArticlesDatabase/ArticlesTable.swift index 226df54ab..b921ac4b8 100644 --- a/Frameworks/ArticlesDatabase/ArticlesTable.swift +++ b/Frameworks/ArticlesDatabase/ArticlesTable.swift @@ -458,6 +458,24 @@ final class ArticlesTable: DatabaseTable { // MARK: - Cleanup + /// Delete articles that we won’t show in the UI any longer + /// — their arrival date is before our 90-day recency window. + /// Keep all starred articles, no matter their age. + func deleteOldArticles() { + queue.runInTransaction { databaseResult in + + func makeDatabaseCalls(_ database: FMDatabase) { + let sql = "delete from articles where articleID in (select articleID from articles natural join statuses where dateArrived