Skip to content

1.3.0.32-dev5-cpr-vcodex-steroids

Choose a tag to compare

Library indexing overhaul — safer, faster, and more reliable on low-memory ESP32

Been working on the library indexing code (the part that scans your SD card, reads EPUB/XTC/TXT metadata, and keeps the library cache in sync). A few things were bugging me — crashes on large libraries, slow parsing, and a couple of bugs that only showed up with custom library root folders. Here's what changed:

Bug fix: Custom library root was ignored on filter change When you switched between "All books", "Favourites", or "Latest read", the device would re-scan the SD card using the default root (/) instead of your configured library folder. So if your books lived in /books/, switching filters could make them disappear. Fixed — it now respects your library root setting everywhere.

Safer EPUB parsing — no more crashes on big libraries The old code would happily try to open and parse every EPUB it found, even when the device was running low on memory. On the ESP32-C3 with ~380 KB of usable RAM, that's a recipe for crashes. Now each book gets a memory check before parsing starts:

EPUB files need at least 40 KB free + 30 KB contiguous block
XTC files need 20 KB free
TXT/Markdown files need 16 KB free
If there's not enough room, the book is skipped with a log message and indexing continues. Much better than a hard crash.

File validation before parsing Added a sanity check before opening any book: the path must be valid, the file must exist, and it must have content (size > 0). Corrupt files or stale cache entries pointing to deleted books are now rejected early, before they can cause trouble deep inside the parser.

Depth limit on directory scanning The directory walker used to recurse indefinitely. A malformed SD card with deeply nested folders could push thousands of paths into memory and crash the device. Now there's a sensible depth limit (8 levels) — more than enough for any realistic library layout like genre/author/series/book.epub.

Incremental sync improvements The sync path (which checks for new/deleted books without a full rescan) got the same depth limit and better error handling. If a newly discovered book fails to parse, it's skipped instead of breaking the whole sync.

Safer library deletion The removeBook() function (used when you delete a book from the library cache) now checks that there's enough free memory before attempting the operation. Loading and saving the entire cache can temporarily double its memory footprint, which was risky on large libraries.