Skip to content

[6.x] Avoid loading the whole container listing in Asset::exists() - #15609

Open
edalzell wants to merge 2 commits into
statamic:6.xfrom
edalzell:fix/asset-exists-skip-listing
Open

edalzell wants to merge 2 commits into
statamic:6.xfrom
edalzell:fix/asset-exists-skip-listing

Conversation

@edalzell

@edalzell edalzell commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Asset::exists() and Asset::metaExists() answered via container()->files(), which unserializes the whole cached recursive listing. Asset::find() calls both, so resolving one asset reference on the front end loaded the full listing. On a 197k-file S3 container that is an 80 MB cache entry and OOMs a 1 GB worker.

Both methods now use the in-memory listing only when this request has already loaded it (AssetContainerContents::isLoaded()), and otherwise do a single disk()->exists() call (one S3 HEAD). CP listings load the listing first, so they keep their zero-extra-IO behaviour.

I skipped the suggested meta-cache shortcut: move() never forgets the old path's meta key, so it would report a moved-away path as existing. A disk check is always right.

Some tests asserted the raw cached listing keys and relied on exists() loading the listing before the .meta file was written. The listing now loads afterwards, so those expectations include the .meta entries, which the listing already filters out on read.

Closes #15607

This branch has not been deployed

No deployments
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.

Asset::exists() loads the entire container listing to check one file

1 participant