Skip to content

Purge cached full images when messages are deleted - #1672

Merged
osyed merged 3 commits into
mainfrom
issue-1656-delete-full-image-cache-phase2
Sep 1, 2026
Merged

Purge cached full images when messages are deleted#1672
osyed merged 3 commits into
mainfrom
issue-1656-delete-full-image-cache-phase2

Conversation

@dnlbui

@dnlbui dnlbui commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

What Changed

This PR makes the Phase 1 full-image cache lifecycle-safe and bounded.

  • purgeImageCaches removes both thumbnail and full-resolution records when image attachments are removed locally or through an accepted delete-for-all event.
  • A late shouldCache guard prevents an in-progress Save from writing a decrypted image back after its message has been deleted.
  • FullImageCache.put() now evicts records in first-in, first-out order using the existing cachedAt index when an incoming image would exceed the 250 MiB budget.
  • Size calculation, FIFO eviction, replacement accounting, and insertion run in one IndexedDB read/write transaction.
  • Cache cleanup remains best-effort and never blocks message deletion or filesystem export.

Fixed Flow

  1. When an image message is deleted, Liberdus removes its thumbnail and URL-keyed full-image records before discarding the attachment metadata.
  2. If that image is still downloading, the late message-state guard skips the final cache write.
  3. When a new image would exceed the full-image budget, Liberdus walks cachedAt from oldest to newest and deletes only enough records to make room.
  4. The incoming image is written in the same transaction, keeping the cache within its configured limit.
  5. Images larger than the entire budget and IndexedDB failures still fall back to the normal uncached Save flow.

Why

Phase 1 persisted decrypted images but did not connect them to message deletion, and its size check permanently stopped caching newer images after the cache filled. Coordinating deletion with pending Saves prevents removed images from being restored, while atomic FIFO eviction keeps the cache useful for newer images without exceeding its application budget.

Validation

  • node --test tests/issue-1656-full-image-cache.test.mjs tests/popup-select-container.test.mjs
  • node --check app.js
  • git diff --check issue-1656-save-image-cache-phase1...HEAD

Depends on #1671

Related to #1656

@dnlbui
dnlbui force-pushed the issue-1656-delete-full-image-cache-phase2 branch from 6415210 to 2514e01 Compare September 1, 2026 20:33
Base automatically changed from issue-1656-save-image-cache-phase1 to main September 1, 2026 23:06
@osyed
osyed force-pushed the issue-1656-delete-full-image-cache-phase2 branch from 9b5085f to c7f5265 Compare September 1, 2026 23:06
@dnlbui dnlbui linked an issue Sep 1, 2026 that may be closed by this pull request
@osyed
osyed merged commit 6b4f109 into main Sep 1, 2026
1 check passed
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.

Avoid re-downloading attachments

2 participants