From d2812fa1321defde8febd8098b41ff2a67cca82a Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 18 Apr 2020 16:59:13 -0700 Subject: [PATCH] Delete old statuses at startup. --- .../ArticlesDatabase/ArticlesDatabase.swift | 1 + .../ArticlesDatabase/ArticlesTable.swift | 26 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift index aac8852db..4b16049d8 100644 --- a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift +++ b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift @@ -273,6 +273,7 @@ public final class ArticlesDatabase { articlesTable.deleteOldArticles() } articlesTable.deleteArticlesNotInSubscribedToFeedIDs(subscribedToWebFeedIDs) + articlesTable.deleteOldStatuses() } } diff --git a/Frameworks/ArticlesDatabase/ArticlesTable.swift b/Frameworks/ArticlesDatabase/ArticlesTable.swift index e87f699e8..68a31189f 100644 --- a/Frameworks/ArticlesDatabase/ArticlesTable.swift +++ b/Frameworks/ArticlesDatabase/ArticlesTable.swift @@ -493,7 +493,7 @@ final class ArticlesTable: DatabaseTable { /// Because deleting articles might block the database for too long, /// we do this in a careful way: delete articles older than a year, /// check to see how much time has passed, then decide whether or not to continue. - /// Repeat for successively shorter time intervals. + /// Repeat for successively more-recent dates. func deleteOldArticles() { precondition(retentionStyle == .syncSystem) @@ -525,6 +525,30 @@ final class ArticlesTable: DatabaseTable { } } + /// Delete old statuses. + func deleteOldStatuses() { + queue.runInTransaction { databaseResult in + guard let database = databaseResult.database else { + return + } + + let sql: String + let cutoffDate: Date + + switch self.retentionStyle { + case .syncSystem: + sql = "select articleID from statuses where dateArrived