Perform a one-time (per local account) cleanup made necessary by the retention policy change — mark articles older than the 90-day window as read. This way users won’t get a flood of old, unread articles when they run this new version.

This commit is contained in:
Brent Simmons 2020-04-19 14:10:12 -07:00
parent b2b000dd2e
commit 75d2158163
4 changed files with 55 additions and 0 deletions

View File

@ -279,7 +279,19 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
webFeedMetadataFile.load()
opmlFile.load()
var shouldHandleRetentionPolicyChange = false
if type == .onMyMac {
let didHandlePolicyChange = metadata.performedApril2020RetentionPolicyChange ?? false
shouldHandleRetentionPolicyChange = !didHandlePolicyChange
}
DispatchQueue.main.async {
if shouldHandleRetentionPolicyChange {
// Handle one-time database changes made necessary by April 2020 retention policy change.
self.database.performApril2020RetentionPolicyChange()
self.metadata.performedApril2020RetentionPolicyChange = true
}
self.database.cleanupDatabaseAtStartup(subscribedToWebFeedIDs: self.flattenedWebFeeds().webFeedIDs())
self.fetchAllUnreadCounts()
}

View File

@ -24,6 +24,7 @@ final class AccountMetadata: Codable {
case lastArticleFetchEndTime
case endpointURL
case lastCredentialRenewTime = "lastCredentialRenewTime"
case performedApril2020RetentionPolicyChange
}
var name: String? {
@ -92,6 +93,14 @@ final class AccountMetadata: Codable {
}
}
var performedApril2020RetentionPolicyChange: Bool? {
didSet {
if performedApril2020RetentionPolicyChange != oldValue {
valueDidChange(.performedApril2020RetentionPolicyChange)
}
}
}
weak var delegate: AccountMetadataDelegate?
func valueDidChange(_ key: CodingKeys) {

View File

@ -277,6 +277,24 @@ public final class ArticlesDatabase {
articlesTable.deleteArticlesNotInSubscribedToFeedIDs(subscribedToWebFeedIDs)
articlesTable.deleteOldStatuses()
}
/// Do database cleanups made necessary by the retention policy change in April 2020.
///
/// The retention policy for feed-based systems changed in April 2020:
/// we keep articles only for as long as theyre in the feed.
/// This change could result in a bunch of older articles suddenly
/// appearing as unread articles.
///
/// These are articles that were in the database,
/// but werent appearing in the UI because they were beyond the 90-day window.
/// (The previous retention policy used a 90-day window.)
///
/// This function marks everything as read thats beyond that 90-day window.
/// Its intended to be called only once on an account.
public func performApril2020RetentionPolicyChange() {
precondition(retentionStyle == .feedBased)
articlesTable.markOlderStatusesAsRead()
}
}
// MARK: - Private

View File

@ -580,6 +580,22 @@ final class ArticlesTable: DatabaseTable {
}
}
}
/// Mark statuses beyond the 90-day window as read.
///
/// This is not intended for wide use: this is part of implementing
/// the April 2020 retention policy change for feed-based accounts.
func markOlderStatusesAsRead() {
queue.runInDatabase { databaseResult in
guard let database = databaseResult.database else {
return
}
let sql = "update statuses set read = true where dateArrived<?;"
let parameters = [self.articleCutoffDate] as [Any]
database.executeUpdate(sql, withArgumentsIn: parameters)
}
}
}
// MARK: - Private