Skip to content

Conversation

@jkmassel
Copy link
Contributor

Description

Extracts AsyncImageKit changes (and suggestions by @kean) from #24972

Testing instructions

I've added SwiftUI Previews covering common cases – if those look good this should be ready to land.

@jkmassel jkmassel added this to the 26.5 milestone Nov 19, 2025
@jkmassel jkmassel requested review from crazytonyli and kean November 19, 2025 00:42
@jkmassel jkmassel self-assigned this Nov 19, 2025
@jkmassel jkmassel added the UI User interface bugs label Nov 19, 2025
@dangermattic
Copy link
Collaborator

2 Warnings
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
⚠️ This PR is assigned to the milestone 26.5. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

private func avatar(url: URL?) -> some View {
let processedURL: URL?
let size = Int(ceil(diameter * UIScreen.main.scale))
let size = Int(ceil(diameter * screenScale))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't related to the PR but I came across it during this PR and figured I'd address it.

@kean
Copy link
Contributor

kean commented Nov 19, 2025

Congratulations on PR number 25,000 🍾

@jkmassel jkmassel force-pushed the add/video-support-to-asyncimageview branch from 511b461 to 0f8a25c Compare November 19, 2025 01:06
@sonarqubecloud
Copy link

@wpmobilebot
Copy link
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number29824
VersionPR #25000
Bundle IDorg.wordpress.alpha
Commit0f8a25c
Installation URL2cu5dn6hn2qbo
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number29824
VersionPR #25000
Bundle IDcom.jetpack.alpha
Commit0f8a25c
Installation URL008c0ge2rslm0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.


let path = self.path(for: key)

try FileManager.default.createDirectory(at: path.deletingLastPathComponent(), withIntermediateDirectories: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store it in the disk cache "forever"

I suggest to store these images in the existing URLCache (see urlSessionWithCache). I recently used URLCache store storing thumbnails for Gutenberg patterns, and it worked pretty well – it doesn't have to be a network response. You can always re-create a preview from AVURLAsset if needed. If these are stored on disk with no cleanup mechanism, it will leave lingering files on disk increasing the space the app takes on disk.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are stored on disk with no cleanup mechanism, it will leave lingering files on disk increasing the space the app takes on disk

The cleanup mechanism is that the system will purge anything in the Caches directory if it needs to, and #24972 adds a cache cleaning mechanism that can do it on user request. There's no such great way to do this with URLCache because under the hood it's a sqlite DB in ~/Library/Caches/com.automattic.jetpack/org.automattic.ImageDownloader for the in-memory DB and stores its files in the same directory. Because that's all managed by urlsessiond I'm not sure we can just erase it?

I'm not sure what we lose by storing the files in ~/Library/Caches/image-cache aside from the automatic cache eviction based on size? But again, if the system needs the space it'll just take it back?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized we could call ImageDownloader.clearURLSessionCache() which is presumably thread-safe so never mind that part. 🤦

It'd be weird/kinda annoying to work it into the cache clearing stuff but it's certainly doable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The longer I look at this the less I feel like URLCache should be used as a general-purpose disk cache?

If I want to store something in it, I need to use a URLResponse alongside my data, but do I also need to manually add fake HTTP headers so that URLCache will store it indefinitely? If I just use an empty URLResponse will it store the results at all? Storing bytes on-disk seems much more straightforward in comparison tbh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be happy to have a custom disk cache with LRU cleanup as an alternative. If you'd like to address it separately, that's OK.

But again, if the system needs the space it'll just take it back?

It's only the last resort. It's best to be a good citizen and not waste space by setting a limit and cleanup up automatically.

@jkmassel jkmassel requested a review from kean November 19, 2025 20:25
func authorize(_ asset: AVURLAsset) -> AVURLAsset {

// Don't authorize requests for other domains
guard asset.url.host() == "public-api.wordpress.com" else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the uploaded videos in support tickets hosted at this domain? This condition may not be true for all videos, though. I believe the videos on the site's Media Library are under the site's domain.

That's probably something we can address later, if the current approach works with the support system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true for the moment, yes.

If we rely on this for more things we'll need to expand it out to i.wp.com (and related domains) but I wanted to keep it small for now and deliberately add more cases as needed.

Copy link
Contributor

@kean kean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but caching could be further improved (left a separate comment).

@jkmassel jkmassel added this pull request to the merge queue Nov 19, 2025
Merged via the queue into trunk with commit 4a20e15 Nov 20, 2025
30 of 32 checks passed
@jkmassel jkmassel deleted the add/video-support-to-asyncimageview branch November 20, 2025 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

UI User interface bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants