Problem #
Measured on a live home directory scan (423,487 directories, 2,237,735 top_files rows):
~/Library/Caches/getael/cache.sqlite3: 2.7 GiB (incl. 333 MiB of unused freelist pages withauto_vacuum = 0)~/Library/Caches/getael/cache.sqlite3-wal: 2.7 GiB (an entire second copy of the database sitting un-truncated on disk)
CacheStore::replace_full_scan (src/cache/mod.rs:400-460) runs DELETE FROM top_files; DELETE FROM directories; and re-inserts all rows inside a single WAL transaction without ever running PRAGMA wal_checkpoint(TRUNCATE) or bounding WAL size via PRAGMA journal_size_limit.
Estimated Savings #
- ~3.0 GiB immediately (~2.7 GiB
-wal+ ~333 MiB freelist).
Proposed Fix #
- Set
PRAGMA journal_size_limit = 33554432;(32 MiB) andPRAGMA auto_vacuum = INCREMENTAL;during schema initialization (src/cache/mod.rs:266-330). - Run
PRAGMA wal_checkpoint(TRUNCATE);andPRAGMA incremental_vacuum;afterreplace_full_scancommits. - Even better: for full scans, bulk-load into a fresh sibling file (
cache.sqlite3.newwithPRAGMA journal_mode = OFFduring insert, then switch toWAL), atomically replacecache.sqlite3, and reopenwrite_conn/read_conn— yielding a zero-fragmentation DB and ~0 B WAL after every full scan. - Add a regression test verifying that after
replace_full_scan,-walsize is truncated and freelist pages are reclaimed.