Add time-based history retention ("keep for N days")#1436
Open
danielsyauqi wants to merge 1 commit into
Open
Conversation
Adds an optional historyKeepDays setting (default 0 = disabled) that automatically removes unpinned history items older than the configured number of days. Pinned items are always preserved. Purging runs on launch, after each new copy, when the setting changes, and on an hourly timer so the limit is enforced while the app stays open and idle. Because expired items are deleted from the SwiftData store, this also reduces the in-memory footprint over long sessions. Adds a 'Keep for' control to the Storage settings pane and tests for the purge behaviour.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements time-based history retention, as discussed in #368. A new optional setting, Keep for (
historyKeepDays), automatically removes unpinned history items whose last copy is older than a configured number of days. Pinned items are never removed.The setting defaults to
0, which disables the time-based limit, so existing behaviour is unchanged unless the user opts in.Motivation
Per the discussion in #368, the maintainer noted that a time-based limit was desirable but should follow the in-memory storage work (#384). Because this implementation deletes expired items from the SwiftData store, it reduces the number of items loaded into memory over long-running sessions rather than adding to the footprint, so it also acts as a partial mitigation for the memory growth reported in #384 and #1240.
To keep the first iteration simple, format-specific retention (separate limits for text vs. images) is intentionally left out; it can be layered on later if there is demand.
Changes
Defaults.Keys.historyKeepDays(Int, default0= disabled).History.purgeExpiredItems()removes unpinned items withlastCopiedAtolder than the cutoff. It is invoked:History.load()),History.add()),0.0) case.Testing
xcodebuild ... buildsucceeds.MaccyTestsrun shows no new failures introduced by this change.Notes for reviewers
HistoryTests, which is currently listed underskippedTestsinMaccy.xctestplan; they therefore will not run in CI as-is. They pass when the class is run directly. Happy to adjust the test plan if preferred.en.lproj) strings are included. The other localizations fall back to English until translated.