Skip to content

feat(app): catalogo offline (Room) + cache copertine persistente + refresh all'apertura#9

Open
fabiodalez-dev wants to merge 1 commit into
mainfrom
feat/offline-catalog-cache
Open

feat(app): catalogo offline (Room) + cache copertine persistente + refresh all'apertura#9
fabiodalez-dev wants to merge 1 commit into
mainfrom
feat/offline-catalog-cache

Conversation

@fabiodalez-dev

Copy link
Copy Markdown
Owner

Implementa una cache locale per non sovraccaricare il server e far funzionare il catalogo offline (richiesta esplicita).

Cosa fa

  • DB locale Room (data/local/): CachedBook + CatalogDao (Flow) + AppDatabase salvano uno snapshot del catalogo. CatalogRepository espone observeCachedCatalog() (offline-first) e refreshCatalog() (scarica la prima pagina e rimpiazza lo snapshot in modo atomico; se la rete fallisce, la cache resta).
  • Home offline-first: lo scaffale "Disponibili ora" si renderizza subito dalla cache (anche senza rete) e si aggiorna in background.
  • Copertine: ImageLoader Coil persistente da 256 MB con respectCacheHeaders(false) → le copertine si scaricano una volta e si riusano, invece di rifarle ogni volta.
  • Refresh all'apertura: ProcessLifecycle ON_START aggiorna la cache quando sei loggato → il catalogo offline resta aggiornato senza martellare il server.

Test (prima suite di test dell'app — 29 test, tutti verdi)

  • CatalogDaoTest (Robolectric, Room in-memory): insert/observe/ordinamento/replaceAll atomico/clear.
  • CachedBookMapperTest: round-trip entity↔summary.
  • BookSummaryTest: disponibilità derivata.
  • StatusMappingTest: regole di annullabilità prenotazione.
  • NetworkUrlTest: derivazione URL istanza.

./gradlew testDebugUnitTest → 29/29 verde. assembleDebug builda. versionCode 4 / 1.2.0.

Note

  • Cache = snapshot prima pagina (≤50) per offline-first dell'Home; la ricerca filtrata/paginata resta online. La paginazione offline completa (RemoteMediator) è un possibile follow-up.
  • Robolectric forzato a SDK 34 (max supportato; app compila su 35).

…fresh on open

Reduces server load and lets the catalog work offline.

- Room cache (data/local/): CachedBook entity + CatalogDao (Flow-backed) +
  AppDatabase store the catalog snapshot locally. CatalogRepository exposes
  observeCachedCatalog() (offline-first) and refreshCatalog() (fetch page 1,
  replace the snapshot atomically; a network failure keeps the existing cache).
- Home is offline-first: it renders the "Available now" shelf from the cached
  snapshot immediately (works with no network) and refreshes in the background.
- Covers: a persistent 256 MB Coil ImageLoader with respectCacheHeaders(false),
  so covers are downloaded once and reused instead of re-fetched every time.
- Refresh on app open: ProcessLifecycle ON_START refreshes the cache when logged
  in, so the offline catalog stays current without hammering the server.
- First unit-test suite for the app (29 tests): Room CatalogDao (Robolectric,
  in-memory), entity↔summary mappers, BookSummary availability, reservation
  cancellable rules, and the URL-derivation helpers.
- versionCode 3 -> 4, versionName 1.1.1 -> 1.2.0.

Verified: assembleDebug builds; testDebugUnitTest green (29/29).
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@fabiodalez-dev, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 31 minutes and 57 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cdfc8485-c0ec-4b2d-82de-397a683cffa4

📥 Commits

Reviewing files that changed from the base of the PR and between 63a9bd4 and 7923205.

📒 Files selected for processing (14)
  • app/build.gradle.kts
  • app/src/main/java/com/pinakes/app/PinakesApplication.kt
  • app/src/main/java/com/pinakes/app/data/local/AppDatabase.kt
  • app/src/main/java/com/pinakes/app/data/local/CachedBook.kt
  • app/src/main/java/com/pinakes/app/data/local/CatalogDao.kt
  • app/src/main/java/com/pinakes/app/data/repository/CatalogRepository.kt
  • app/src/main/java/com/pinakes/app/di/ServiceLocator.kt
  • app/src/main/java/com/pinakes/app/ui/screens/home/HomeViewModel.kt
  • app/src/test/java/com/pinakes/app/BookSummaryTest.kt
  • app/src/test/java/com/pinakes/app/CachedBookMapperTest.kt
  • app/src/test/java/com/pinakes/app/CatalogDaoTest.kt
  • app/src/test/java/com/pinakes/app/NetworkUrlTest.kt
  • app/src/test/java/com/pinakes/app/StatusMappingTest.kt
  • gradle/libs.versions.toml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/offline-catalog-cache

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@fabiodalez-dev

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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