refactor: unify book cache clearing for epub, txt, and xtc files#1875
refactor: unify book cache clearing for epub, txt, and xtc files#1875WuTofu wants to merge 6 commits into
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🧰 Additional context used🧠 Learnings (5)📚 Learning: 2026-02-23T06:18:08.408ZApplied to files:
📚 Learning: 2026-02-27T22:49:59.600ZApplied to files:
📚 Learning: 2026-03-02T10:14:16.036ZApplied to files:
📚 Learning: 2026-03-28T11:06:29.611ZApplied to files:
📚 Learning: 2026-04-12T12:28:33.205ZApplied to files:
🔇 Additional comments (1)
📝 WalkthroughWalkthroughAdds Txt::clearCache(), introduces a unified clearBookCache(path) dispatcher and isBookCacheDirectoryName(), and updates browser, settings, CrossPointWebServer, and WebDAV handlers to call the new API instead of EPUB-only cache-clearing helpers. ChangesUnified Book Cache Clearing Refactor
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant BookCacheUtils
participant Backend
Client->>Server: upload/rename/move/delete request
Server->>BookCacheUtils: clearBookCache(path)
BookCacheUtils->>Backend: select backend by extension and call clearCache()
Backend-->>BookCacheUtils: result
BookCacheUtils-->>Server: done
🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/util/BookCacheUtils.cpp`:
- Around line 9-20: The unconditional success log in clearBookCache is
misleading because Epub::clearCache, Xtc::clearCache and Txt::clearCache return
status that is ignored; update clearBookCache to capture each call's
boolean/return value (e.g. auto ok = Epub(path, "/.crosspoint").clearCache()),
then only call LOG_DBG("BookCache", "Cleared metadata cache for: %s", ...) when
ok is true and call LOG_ERR("BookCache", "Failed to clear cache for: %s", ...)
(or return early) when ok is false; apply the same pattern for Epub, Xtc and Txt
so success/failure logs reflect the actual result.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 82b473a9-cbec-4490-ab19-f1cdd8fb1cac
📒 Files selected for processing (9)
lib/Txt/Txt.cpplib/Txt/Txt.hsrc/activities/browser/OpdsBookBrowserActivity.cppsrc/activities/settings/ClearCacheActivity.cppsrc/network/CrossPointWebServer.cppsrc/network/WebDAVHandler.cppsrc/network/WebDAVHandler.hsrc/util/BookCacheUtils.cppsrc/util/BookCacheUtils.h
💤 Files with no reviewable changes (1)
- src/network/WebDAVHandler.h
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: cppcheck
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2026-02-23T06:18:08.408Z
Learnt from: raygan
Repo: crosspoint-reader/crosspoint-reader PR: 1116
File: src/activities/settings/WallabagSettingsActivity.cpp:57-75
Timestamp: 2026-02-23T06:18:08.408Z
Learning: When navigating from a settings activity to KeyboardEntryActivity (e.g., KOReaderSettingsActivity, WallabagSettingsActivity), call exitActivity() on the parent before calling enterNewActivity(new KeyboardEntryActivity(...)). The KeyboardEntryActivity should then call exitActivity() via its callbacks to return to the parent. Note: ConfirmationActivity does not require exitActivity() before entering KeyboardEntryActivity. Apply this pattern to similar settings activities in this module.
Applied to files:
src/activities/settings/ClearCacheActivity.cpp
📚 Learning: 2026-02-27T22:49:59.600Z
Learnt from: ngxson
Repo: crosspoint-reader/crosspoint-reader PR: 1218
File: src/activities/ActivityManager.cpp:254-265
Timestamp: 2026-02-27T22:49:59.600Z
Learning: In this codebase, assertions are always enabled (no NDEBUG). Use assert() to crash on programmer errors and surface logic bugs during development and in production builds. Do not rely on asserts for runtime error handling; they should enforce invariants that must always hold. Keep asserts side-effect free and inexpensive, and avoid relying on them for user-visible failures. Include <cassert> where appropriate and document the invariant being tested.
Applied to files:
src/activities/settings/ClearCacheActivity.cpplib/Txt/Txt.cppsrc/util/BookCacheUtils.cppsrc/network/CrossPointWebServer.cppsrc/network/WebDAVHandler.cppsrc/activities/browser/OpdsBookBrowserActivity.cpp
📚 Learning: 2026-03-02T10:14:16.036Z
Learnt from: Uri-Tauber
Repo: crosspoint-reader/crosspoint-reader PR: 1245
File: lib/Epub/Epub/Section.cpp:277-308
Timestamp: 2026-03-02T10:14:16.036Z
Learning: Guideline: Strengthen serialization::readString to defend against unbounded growth when reading from disk data. Implement and enforce a maximum allowed length (e.g., a configured or reasonable constant) and validate the incoming length before resizing or allocating. Audit all call sites (e.g., BookMetadataCache, TextBlock, KOReaderCredentialStore, Section cache readers) to ensure they do not rely on unbounded len-based resizing. If the readString API must remain, add internal safeguards (bounds checks, length validation, and error handling) so per-call-site validations are not required. Ensure Section cache files remain versioned (SECTION_FILE_VERSION) and parameter mismatches invalidate caches, but do not rely on unsafe allocations; prefer safe, bounded reads with explicit errors on invalid data.
Applied to files:
src/activities/settings/ClearCacheActivity.cpplib/Txt/Txt.cppsrc/util/BookCacheUtils.cppsrc/network/CrossPointWebServer.cppsrc/network/WebDAVHandler.cppsrc/activities/browser/OpdsBookBrowserActivity.cpp
📚 Learning: 2026-03-28T11:06:29.611Z
Learnt from: pablohc
Repo: crosspoint-reader/crosspoint-reader PR: 1488
File: src/activities/home/HomeActivity.cpp:92-95
Timestamp: 2026-03-28T11:06:29.611Z
Learning: When reviewing crosspoint-reader code, avoid flagging a missing `renderer.displayBuffer()` call immediately after `GUI.drawPopup()` / `BaseTheme::drawPopup()`: `BaseTheme::drawPopup()` already calls `renderer.displayBuffer()` before returning, so the popup is guaranteed to be flushed to the e-ink panel before subsequent blocking work begins. Conversely, do not require a `renderer.displayBuffer()` call after `fillPopupProgress()`; it intentionally does not flush, so intermediate progress-bar updates may not appear unless the update granularity warrants an explicit flush elsewhere.
Applied to files:
src/activities/settings/ClearCacheActivity.cpplib/Txt/Txt.cppsrc/util/BookCacheUtils.cppsrc/network/CrossPointWebServer.cppsrc/network/WebDAVHandler.cppsrc/activities/browser/OpdsBookBrowserActivity.cpp
📚 Learning: 2026-04-12T12:28:33.205Z
Learnt from: Uri-Tauber
Repo: crosspoint-reader/crosspoint-reader PR: 1629
File: src/activities/home/HomeActivity.cpp:119-120
Timestamp: 2026-04-12T12:28:33.205Z
Learning: When reviewing code in this repository (C/C++ sources), set review comment severity according to this policy:
- Use **Major** (🟠) only for defects with realistic risk of crash, out-of-memory (OOM), invalid pointer dereference, data corruption, or other severe issues that are unlikely to be caught in casual/manual device testing.
- Use **Minor** or informational for UX gaps, logic edge-cases, style issues, or missing feature completeness that the author can verify (or has verified) through normal device use.
- Do **not** escalate severity to Major based on behavioral/UX observations alone; assume the author has already tested the feature on their own device and only treat issues as Major if they match the high-risk defect categories above.
Applied to files:
src/activities/settings/ClearCacheActivity.cpplib/Txt/Txt.cppsrc/util/BookCacheUtils.cppsrc/util/BookCacheUtils.hlib/Txt/Txt.hsrc/network/CrossPointWebServer.cppsrc/network/WebDAVHandler.cppsrc/activities/browser/OpdsBookBrowserActivity.cpp
🔇 Additional comments (7)
lib/Txt/Txt.h (1)
25-25: LGTM!Clean declaration, consistent with the
setupCacheDir()/generateCoverBmp()sibling pattern.lib/Txt/Txt.cpp (1)
158-171: LGTM!Implementation is clean and idempotent: returns success immediately when the cache directory doesn't exist, delegates removal to
Storage.removeDir(consistent with how EPUB/XTC caches are cleared), and propagates failure through the return value.src/activities/settings/ClearCacheActivity.cpp (1)
97-99: LGTM!The
txt_prefix correctly matches the cache directory naming scheme (txt_{hash}) produced by theTxtconstructor, keeping this scan in sync with the newTxt::clearCache()introduction.src/util/BookCacheUtils.h (1)
1-7: LGTM!Minimal, well-documented header. The comment accurately reflects the extension-dispatch behaviour implemented in the
.cpp.src/activities/browser/OpdsBookBrowserActivity.cpp (1)
279-280: LGTM!Switching to
clearBookCache(filename)is correct here;filenameis always*.epub(hardcoded extension at line 267), so the dispatch inBookCacheUtils.cppwill always route toEpub::clearCache()— semantically identical to the old call, now unified.src/network/WebDAVHandler.cpp (1)
386-391: LGTM!The
clearBookCache(path.c_str())placement (after the_putOkguard, before the HTTP response) correctly invalidates stale cache for all recognised overwrite scenarios.src/network/CrossPointWebServer.cpp (1)
713-716: LGTM!
clearBookCacheis called after confirmingstate.error.isEmpty()(upload succeeded), and the path construction mirrors the original file path. Correct placement across all five upload/rename/move/delete paths in this file.
|
@znelson I am new here. I'm not quite sure about the timing between RC and the final release Before you release v1.3.0, I hope I can fix the issue where the book cache didn't get deleted when deleting a folder introduced by #1803. Would you mind reviewing this pr if the final release is coming soon? |
e1ecfee to
d7ebb9a
Compare
|
@Uri-Tauber, @pablohc. If you are not too busy, could you review this pr? This pr not only added |
|
@WuTofu Nice work — though I think this should probably wait until after release 1.3. |
Summary
What is the goal of this PR?
Implements unified book cache invalidation method for text, epub, and xtc files content paths to ensure cache is cleared whenever files are uploaded, renamed, moved, or deleted.
What changes are included?
Txt::clearCache()support inTxt.cpp/Txt.hclearBookCache()helper inBookCacheUtils.cpp/BookCacheUtils.htxt_cache directories as wellAdditional Context
I will work on
FileBrowserActivity.cppas part of #1803's follow-up after this pr.AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? PARTIALLY