Skip to content

Add time-based history retention ("keep for N days")#1436

Open
danielsyauqi wants to merge 1 commit into
p0deje:masterfrom
danielsyauqi:feature/history-keep-days
Open

Add time-based history retention ("keep for N days")#1436
danielsyauqi wants to merge 1 commit into
p0deje:masterfrom
danielsyauqi:feature/history-keep-days

Conversation

@danielsyauqi

Copy link
Copy Markdown

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, default 0 = disabled).
  • History.purgeExpiredItems() removes unpinned items with lastCopiedAt older than the cutoff. It is invoked:
    • on launch (History.load()),
    • after each new copy (History.add()),
    • when the setting changes, and
    • on an hourly timer, so the limit is enforced while the app stays open and idle (the case the count-based limit cannot cover).
  • A Keep for control in the Storage settings pane, alongside Size, showing "Disabled" when set to 0.
  • English strings for the new control.
  • Unit tests covering removal of expired items, preservation of recent and pinned items, and the disabled (0) case.

Testing

  • xcodebuild ... build succeeds.
  • The new tests pass when run directly.
  • The full MaccyTests run shows no new failures introduced by this change.

Notes for reviewers

  • The new tests are added to HistoryTests, which is currently listed under skippedTests in Maccy.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.
  • Only English (en.lproj) strings are included. The other localizations fall back to English until translated.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant