Asset::exists() loads the entire container listing to check one file
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 76/100
Direzione di ricerca
Read src/Assets/Asset.php around exists() and metaExists(), then trace the cache and listing behavior in AssetContainerContents. Start with tests/Assets/AssetTest.php and add coverage for the meta-cache, disk fallback, and missing-path cases described in the issue. Done means existence checks avoid loading the full listing when possible and the tests pass.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug description
Asset::exists() (src/Assets/Asset.php:224) is $this->container()->files()->contains($path). files() resolves through AssetContainerContents::all(), which reads the whole cached recursive listing of the container into memory. AssetRepository::findById() → AssetContainer::asset() calls exists() on every lookup, so resolving a single asset reference on the front end costs a full listing load.
On a large S3 container this is fatal. One production site has a private container with 197,603 files; the cached listing (asset-list-contents-<handle>) is an 80 MB serialized string in Redis, and unserializing it pushes a PHP-FPM worker past a 1 GB memory_limit:
Allowed memory size of 1073741824 bytes exhausted (tried to allocate 80320709 bytes) at vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php:124
Any page that renders an asset from that container pays this, not just the CP.
How to reproduce
- Container on an S3 disk with a large number of files (tens of thousands is enough to see it; 197k reproduces the fatal at 1 GB).
STATAMIC_STACHE_FILE_WATCHER=falseso the listing is cached forever.Asset::find('private::some/file.jpg')from a front-end template or tinker and watch memory: the whole listing is loaded to answer onecontains().
Logs
See above.
Environment
Statamic 6.35.0, Laravel 11, PHP 8.3, Redis cache, S3 (Flysystem v3) container, cache_meta true.
Installation
Existing Laravel app
Additional details
Suggested fix: make exists() answer without the listing when it can.
- If
cache_metais on andcacheStore()->has($this->metaCacheKey())(meta cache is written only for assets that exist), return true without touching the listing. - If the listing is already loaded in memory for this request (
AssetContainerContents::$filesis set, or Blink has it), use it as today. - Otherwise fall back to a single
$this->disk()->exists($path)(one S3HEAD) instead of loading the listing.
The same pattern applies to metaExists() (src/Assets/Asset.php:316), which calls container()->metaFiles() and so also loads the full listing. A disk check on metaPath() works there too.
Tests to add in tests/Assets/AssetTest.php: exists() returns true from the meta cache without calling files(); falls back to the disk check when nothing is cached; still returns false for a missing path. Related: #11998 (meta as content) and a separate issue for excluding .meta files from the listing.
- Lingua principale
- PHP
- Stelle
- 4.9k
- Fork
- 647
- Merge medio
- 1g 45m
- PR unite (30g)
- 221
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di statamic/cms
-
forms ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
accessibility
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
antlers
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
Nav: link to the site root with an anchor (/#section) gets is_parent on every pageForse già presa @duncanmcclean l’ha presa oggi. Apertanavigations
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
Multiple Choice and Checkboxes no longer offer "Inline", but the default views still use itForse già presa @duncanmcclean l’ha presa oggi. Apertaforms
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di statamic/cms
Issue simili
-
sync-en
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
Selection on a line without a docblock tag drops trailing characters (data provider attribute)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
vimeo/psalm#15150 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
taskforcesh/bullmq#5238 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects itForse già presa @bfs2021 l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Automattic/jetpack#55517 ·
I maintainer di solito rispondono entro 1 giorno