Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set image expiry #1565

Closed
alltheseas opened this issue Sep 29, 2023 · 7 comments
Closed

Set image expiry #1565

alltheseas opened this issue Sep 29, 2023 · 7 comments
Assignees

Comments

@alltheseas
Copy link
Collaborator

alltheseas commented Sep 29, 2023

With the exception of PFPs, set an image auto-expiry date for images, and videos to control damus cache size.

Related: fix clear cache #1472

Explore storage visualization, preferences #1554

@danieldaquino
Copy link
Contributor

Investigating this now!

@danieldaquino
Copy link
Contributor

I created a patch to address this!

I set:

  • 1 week for images on notes
  • 2 weeks for profile banners
  • Never for profile pictures

All code, testing, and discussion was sent via email, and can be viewed here: https://groups.google.com/a/damus.io/g/patches/c/cGZcTD8zYLE

@alltheseas
Copy link
Collaborator Author

I created a patch to address this!

I set:

  • 1 week for images on notes
  • 2 weeks for profile banners
  • Never for profile pictures

All code, testing, and discussion was sent via email, and can be viewed here: https://groups.google.com/a/damus.io/g/patches/c/cGZcTD8zYLE

Nice!

Does it include videos as well?

@danieldaquino
Copy link
Contributor

Thanks @alltheseas, that's a good point. The patch does not currently include videos.

However, I examined the code, and it does not seem like videos are cached at all. 🤔

I already looked at:

  • DamusViewPlayer.swift
  • DamusVideoPlayerViewModel.swift
  • AVPlayer
  • ImageCarousel.swift

In #1472 I remember I did not see any evidence that videos are being cached either, even though someone mentioned that they are.

@jb55, would you happen to know if we cache videos and — if we do — in which part of the code we do that? Am I looking at the right places?

@jb55
Copy link
Collaborator

jb55 commented Oct 14, 2023 via email

@jb55
Copy link
Collaborator

jb55 commented Oct 14, 2023 via email

@danieldaquino
Copy link
Contributor

danieldaquino commented Oct 16, 2023

maybe check the container storage if you find anything?

I checked the container of the normal Damus instance running on my phone (4GB+ of data) and could not find any videos. Here is what I tried:

  1. Ran find . at the root of the container and read all file paths. Nothing stood out as being videos.
  2. Ran file * on some folders that looked like caches and manually inspected output. No video files detected
  3. Ran find . -type f -exec file {} \; | grep video at the root of the container to see if it detects any files with video content. Output was blank
  4. Ran find . -type f -exec file -b {} \; at the root of the container and skimmed through output. Saw a lot of images, some other file formats, but no videos

@jb55 jb55 closed this as completed in 82fba88 Oct 17, 2023
suhailsaqan pushed a commit to suhailsaqan/damus that referenced this issue Oct 29, 2023
This commit adds expiry dates for images added to the Kingfisher cache.
The expiry date depends on the context of the image:

- Images from notes expire after a week
- Images from profile banners expire after two weeks
- Profile pictures never expire.

Test
----

Device: iPhone 14 Pro (Simulator), iOS: 17.0
Special remarks: Requires minor local mods and debugger connection
Steps:

1. Locally change the note image expiry to 5 seconds
2. Set a breakpoint in `removeExpiredValues` function in `DiskStorage.swift` in Kingfisher
3. Disable breakpoints for now
4. Start Damus and go to the profile feed of someone new
5. Scroll down through the images for about a minute
6. Turn on breakpoints
7. Switch to a different app in the simulator (Make Damus go to background mode)
8. Wait for a few seconds. Debugger should hit the breakpoint set. PASS
9. Take note of the fileURLs of the images being deleted
10. Go to that directory where the fileURLs are in via Finder
11. Look at some of the images being deleted. Perhaps save a copy for comparison.
12. Turn off breakpoints, resume execution and go back to Damus
13. Scroll back up. Some images there should match the images being automatically deleted from the cache. PASS

Closes: damus-io#1565
Changelog-Added: Add expiry date for images in cache to be auto-deleted after a preset time to save space on storage
Signed-off-by: Daniel D’Aquino <[email protected]>
Reviewed-by: William Casarin <[email protected]>
Signed-off-by: William Casarin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants