Asset::exists() loads the entire container listing to check one file
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 76/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- PHP
- Étoiles
- 4.9k
- Forks
- 647
- Merge moyen
- 1 j 45 min
- PR mergées (30 j)
- 221
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de statamic/cms
-
forms ui
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
Les mainteneurs répondent en général sous 1 jour
-
accessibility
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Les mainteneurs répondent en général sous 1 jour
-
antlers
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
Les mainteneurs répondent en général sous 1 jour
-
Nav: link to the site root with an anchor (/#section) gets is_parent on every pagePeut-être pris @duncanmcclean l’a pris aujourd’hui. Ouvertenavigations
Difficulté 2/5 1-3 heures Accessibilité débutants 35/100
Les mainteneurs répondent en général sous 1 jour
-
Multiple Choice and Checkboxes no longer offer "Inline", but the default views still use itPeut-être pris @duncanmcclean l’a pris aujourd’hui. Ouverteforms
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de statamic/cms
Issues similaires
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Les mainteneurs répondent en général sous 1 jour
-
documentation good first issue help wanted up-for-grabs
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
AnikethTS/RunnerDeck#307 ·
Les mainteneurs répondent en général sous 1 jour
-
sync-en
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
sync-en
Difficulté 1/5 Moins d'une heure Accessibilité débutants 86/100
Les mainteneurs répondent en général sous 1 jour
-
[Sync EN] Clarify the exampleOuverteПеревод устарел
Difficulté 1/5 Moins d'une heure Accessibilité débutants 65/100
Les mainteneurs répondent en général sous 1 jour