Skip to content

enquire_archive daily: read each archive file once - #339

Merged
jeyrb merged 1 commit into
rhizomatics:mainfrom
lollox80:perf/archive-daily-cache
Nov 24, 2026
Merged

jeyrb merged 1 commit into
rhizomatics:mainfrom
lollox80:perf/archive-daily-cache

Conversation

@lollox80

Copy link
Copy Markdown
Collaborator

Closes #338.

verbosity: daily without a limit opened every archive file in the range on every call. Archive files are
written once and never changed, so ArchiveDirectory now keeps a daily record per file name (_daily_record:
created, outcome, priority, deliveries sent/failed, scenario names) and list_daily_records opens only files it
has not seen. Files gone from the directory (purge) are dropped from the cache on the next scan.

  • Same totals as before: summarize_by_day reads the record exactly as it reads the full file (tested).
  • Filters (after, before, period, outcome, priority) work on the record; limit keeps the old path.
  • Memory: ~1.8 MB for 6,900 notifications.
  • Benchmark on 6,900 synthetic files: 0.97 s before, 0.51 s first call, 0.10 s after (the rest is scandir +
    stat). On my HA the month took 12.8 s before.

Tests: test_action_reads_each_file_once, test_action_cached_matches_filters_and_purge,
test_daily_record_keeps_what_the_summary_needs, test_daily_records_outside_home_assistant.
CI replica: ruff check/format, codespell, mypy, ty green; pytest green on HA 2026.10 and HA 2026.5 (plus the four new tests);
archive.py new lines covered.

verbosity daily without a limit opened every archive file in the range on
every call - 13 s for a month (about 6,900 files) on a Raspberry Pi class
host. Archive files are written once and never changed, so the part the
daily totals and the list filters need (created, outcome, priority,
deliveries sent/failed, scenario names) is now kept in memory by file
name; the next call opens only the files archived since. Names gone from
the directory (purge_archive) drop out of the cache on the next scan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xb3AAHgGH8CosCCseNn4yt
@jeyrb
jeyrb merged commit 5ba62a9 into rhizomatics:main Nov 24, 2026
18 checks passed
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.

enquire_archive verbosity: daily reads the whole archive on every call (13 s for a month)

2 participants