8000 perf(storage): 空闲时跳过未变化的报表缓存与账本写入 by InfinityPacer · Pull Request #22 · InfinityPacer/meterleaf · GitHub
[go: up one dir, main page]

Skip to content

perf(storage): 空闲时跳过未变化的报表缓存与账本写入 - #22

Merged
InfinityPacer merged 1 commit into
mainfrom
perf/reduce-idle-writes
Sep 30, 2026
Merged

InfinityPacer merged 1 commit into
mainfrom
perf/reduce-idle-writes

Conversation

@InfinityPacer
Copy link
Copy Markdown
Owner

Problem

Meterleaf wrote about 6–8 GB/day to the NAS SSD even when nobody had the page open. File-level inotify counts showed where it went:

  • Every 5 minutes, the scheduled report refresh recomputed all cached reports and saved the entire view cache again, even when the results were identical. Together with the report index update, this produced a burst of about 4,900 page writes each time.
  • Every minute, the background sync wrote to the ledger WAL continuously.

Opening the page already returns the cached result first and then refreshes in the background, so the 5-minute timer was not needed to keep the page fresh.

Changes

  • Report cache: each entry records a content digest (excluding the per-level asOf, sync and reportStatus). An identical refresh no longer writes to the view-cache database, and the digest is also computed when the cache is restored at startup.
  • Ledger: sync_state is written only when the value changes, and account upserts now use IS NOT for a NULL-safe comparison. Real changes still bump the revision and fingerprint, and the report projection still picks them up.
  • Default report refresh interval: from 5 minutes to 1 day. It is only a fallback; opening the page still refreshes immediately.
  • Default background sync interval: from 60 seconds to 15 minutes. It stays 15 seconds while the page is open.
  • Where the defaults are updated: compose.yaml, .env.example and the deployment guide. Deployments that already set these values explicitly in .env are not affected.
  • Version: 0.6.4, with the CHANGELOG updated.

Verification

  • bun run typecheck: passes.
  • bun test tests: 346 pass, 0 fail.
  • bun run build: succeeds.
  • git diff --check: no problems.
  • New tests:
    • An identical refresh, within one process or after a restart, writes nothing to the view cache; a changed result is written and restored.
    • Replaying identical accounts, quotas and state leaves the ledger's total_changes unchanged; real changes still propagate.
    • Removing either guard makes the corresponding test fail.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@InfinityPacer
InfinityPacer merged commit 159944e into main Sep 30, 2026
2 checks passed
@InfinityPacer
InfinityPacer deleted the perf/reduce-idle-writes branch September 30, 2026 14:26
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

0