Skip to content

fix: invalidate download cache after backup restore#3096

Open
leodyversemilla07 wants to merge 1 commit intomihonapp:mainfrom
leodyversemilla07:fix/invalidate-download-cache-after-backup-restore
Open

fix: invalidate download cache after backup restore#3096
leodyversemilla07 wants to merge 1 commit intomihonapp:mainfrom
leodyversemilla07:fix/invalidate-download-cache-after-backup-restore

Conversation

@leodyversemilla07
Copy link
Copy Markdown
Contributor

Summary

Fixes #2574

Automatically invalidate the download cache after backup restore to ensure the UI correctly reflects which chapters are actually downloaded.

Root Cause

When a backup is restored, the download cache is not rebuilt. This causes:

  • Downloaded chapters showing as 'not downloaded' in the UI
  • Errors when attempting to download already-downloaded chapters
  • Users having to manually invalidate the cache via Settings → Advanced

The download cache maintains an in-memory mapping of downloaded chapters. After backup restore, the cache remains empty even though downloaded files exist in storage, causing it to be out of sync with reality.

Changes

  • Added automatic download cache invalidation after backup restore completes
  • Only invalidates when library entries are restored (no point if no manga data was restored)
  • Wrapped in try-catch to prevent restore failure if cache invalidation encounters an error
  • Follows the same pattern used for storage location changes

Testing

  • Self-reviewed the change
  • Follows existing patterns: cache invalidation already used in \SettingsAdvancedScreen.kt\ and on storage changes
  • Low risk: just calling existing, well-tested \invalidateCache()\ method

Related

This is similar to how the cache is automatically invalidated when storage location changes (see \DownloadCache.kt:131)

Fixes downloads showing as 'not downloaded' after backup restore even when files exist on disk.

The download cache was not being rebuilt after backup restoration, causing it to be out of sync with the actual downloaded files in storage. This led to:
- All chapters showing as 'not downloaded' in the UI
- Errors when trying to download already-downloaded chapters
- Users having to manually invalidate cache via Advanced Settings

After restoring library entries, the download cache is now automatically invalidated, triggering a rescan of the downloads directory to rebuild the cache. This ensures the UI accurately reflects which chapters are actually downloaded.

Fixes mihonapp#2574
@leodyversemilla07 leodyversemilla07 force-pushed the fix/invalidate-download-cache-after-backup-restore branch from 7d08212 to 913e934 Compare March 26, 2026 08:44
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.

Invalidate downloads cache when restoring backup

1 participant