damus icon indicating copy to clipboard operation
damus copied to clipboard

Fix Kingfisher cache clearing

Open alltheseas opened this issue 1 month ago • 3 comments

Summary

fixes kingcache media/image cache clearing bug

image

Checklist

  • [ ] I have read (or I am familiar with) the Contribution Guidelines
  • [x] I have tested the changes in this PR - *only in Xcode iOS Simulator
  • [ ] I have profiled the changes to ensure there are no performance regressions, or I do not need to profile the changes.
    • Utilize Xcode profiler to measure performance impact of code changes. See https://developer.apple.com/videos/play/wwdc2025/306
    • If not needed, provide reason:
  • [x] I have opened or referred to an existing github issue related to this change: https://github.com/damus-io/damus/issues/2861
  • [x] My PR is either small, or I have split it into smaller logical commits that are easier to review
  • [ ] I have added the signoff line to all my commits. See Signing off your work
  • [ ] I have added appropriate changelog entries for the changes in this PR. See Adding changelog entries
    • [ ] I do not need to add a changelog entry. Reason: [Please provide a reason]
  • [ ] I have added appropriate Closes: or Fixes: tags in the commit messages wherever applicable, or made sure those are not needed. See Submitting patches

Test report

Tested in Xcode iOS Simulator & MacOS working directory terminal.

If you want to capture logs yourself, run this in a terminal window before pressing the button:

  log stream --level info --style compact --predicate 'subsystem == "com.jb55.damus" && category == "storage"'

  Keep the command running and tap Clear Cache in the simulator; those messages will stream by. That confirms Kingfisher and the cache directory both get cleared.

Device: 17 Pro iOS Simulator

iOS: iOS 26

Damus: 1.15 (1) 8122a8a5

Steps: run terminal log stream command above, disable image blur, go to universe view, scroll for 30 seconds to accumulate sufficient media for kingfisher. go to settings -> appearance -> clear cache, verify in terminal

Results:

  • [] PASS
  • [x] Partial PASS
    • Details: needs on phone confirmation/verificaiton (was not able to compile to my phone)

Other notes

~1 minute of scrolling without blur in universe view generated over 200 MB of kingfisher cache size!

alltheseas avatar Oct 17 '25 21:10 alltheseas

@alltheseas, unfortunately it does not seem like this fixes the main issue. That part of the cache clearing seems to have been working prior to the PR.

I locally downloaded the changes and removed all functional changes — leaving only the new logging code, and reran the test. The results were the same as posted.

Device: iPhone simulator iOS: iOS 26 Damus: 138f0f2fa99b487c8652336e3a1f9205eabf5c0b (Includes only the logs but no functional changes) Steps:

  1. Scroll through the timeline
  2. Run log stream --level info --style compact --predicate 'subsystem == "com.jb55.damus" && category == "storage"' to get logs
  3. Clear cache in settings

Results: Cache appears to clear; Logs have the same pattern as the PR description Screenshot 2025-10-17 at 16 13 30

I believe the main issue of https://github.com/damus-io/damus/issues/2861 is in a different place and more investigation would be needed to find out where it is and reproduce it.

@jb55, any other thoughts?

danieldaquino avatar Oct 17 '25 23:10 danieldaquino

@danieldaquino I compiled Damus from xcode to my local iOS device, and confirmed clear cache works on device. Results were 12.5 GB is reduced to 450-550 MB as displayed in settings -> storage -> damus in iOS menu on device.

New commit that works for me on a physical device/ iPhone 13 mini is https://github.com/damus-io/damus/pull/3266/commits/5656b59d3fc39b1ebd3bbff8346fb80da7923abf

As to why there are ~~500 MB or so remaining, it has to do with iOS caching

I'm figuring out why the reported 437 MB for app storage is so much higher
  than the measured 22 MB from the main app and shared containers. It seems
  like the iOS system may be including caches, extensions, or stale indexes
  like SplashBoard or System Data that aren't cleared instantly. To clarify
  this, I'll suggest the user check iPhone Storage again after some time or
  try offloading and reinstalling the app, explaining the difference between
  measured container sizes and the OS storage display.

─ Worked for 34s ───────────────────────────────────────────────────────────────

• Here’s what we measured after that last Clear Cache run (all paths checked
  directly on the device):

  - Main app container (com.jb55.damus2) totals ~21 MB. Biggest pieces now
    are the TipKit database (~2.5 MB + WAL/SHM ~3 MB), your HTTPStorage WAL
    (~1.7 MB), and the SplashBoard launch snapshots (~16 MB). tmp/ is completely
    empty.
  - Shared app-group container (group.com.damus) is back to essentially
    nothing: a fresh 96 KB data.mdb, lock.mdb, and empty Kingfisher directories.
    Kingfisher cache is gone, and LMDB will only regrow as you fetch content.
  - Share / notification / highlighter extensions together hold only a couple of
    megabytes, with their Kingfisher defaults now clean.

  So we’re down to roughly 25 MB of real data across all Damus containers. iOS
  is still reporting 437.6 MB because it hasn’t re-indexed yet. Two ways to
  force the recalculation:

  1. Go to Settings → General → iPhone Storage → Damus, wait until the spinning
     gear beside “Documents & Data” stops. Sometimes backing out and re-entering
     that screen a couple of times does it.
  2. If the number stays stuck, rebooting the device (or completely offloading/
     reinstalling the app) makes Storage re-scan immediately.

  Once the OS rescans, expect the reported size to drop to something close to
  what we’re seeing—roughly the TipKit/HTTP storage files plus the unavoidable
  SplashBoard snapshots. Let me know after the number updates; I can re-check
  the containers again if anything looks off.

alltheseas avatar Oct 20 '25 20:10 alltheseas

f6426dab is re-based to local relay model branch @danieldaquino.

Tested via xcode to my device. Device successfully clears cache.

image image

alltheseas avatar Oct 25 '25 23:10 alltheseas