Stache index built on first use leaves a stale file collection that the next `warm()` indexes from
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 58/100
Línea de trabajo
Start in Store.php, where getItemsFromFiles() assigns $this->fileItems and warm() sets $shouldCacheFileItems before building indexes. Check the reset behaviour in clear() and in the store reset used between jobs and Octane requests, and confirm ContainerAssetsStore reads $fileItems the same way. Reproduce with the steps in the issue in a test under tests/Stache. Done when a term file written after an empty query is indexed by a later warm(), and the existing tests/Stache suite still passes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug description
Store::getItemsFromFiles() assigns $this->fileItems on every call, including outside a warm. warm() sets $shouldCacheFileItems and then reuses that collection for every index it updates, nulling it only after the indexes are built. Nothing else resets it: clear() does not, and neither does the store reset that runs between queue jobs and between Octane requests (Statamic\Stache\ServiceProvider::resetMemoizedStateBetweenJobs() and resetMemoizedStateBetweenOctaneRequests()), which clears each store's paths and indexes.
When an index is built on first use while a taxonomy is empty, the empty collection stays in $fileItems. A later warm() builds every index from that collection, so a term file written in between is missing from the title index and Term::whereTaxonomy() does not return it. Since #15897 (v6.43.0) clear() keeps the record of used indexes, so a clear() followed by warm() also builds the title index, and builds it from the stale collection. On v6.42.0 the same sequence returns the term.
Expected: a warm() indexes the files on disk when it runs.
Store.php is byte-identical on v6.43.0, v6.43.1, v6.43.2 and 6.x.
How to reproduce
On v6.43.1, in a test that extends Tests\TestCase and uses PreventSavingStacheItemsToDisk, with an empty tags taxonomy whose terms directory is a temporary directory:
- Read
Stache::store('terms')->store('tags')->index('title')->keys(). It is empty, and the store now holds an empty$fileItems. - Write
tags/default_news.yamlcontainingtitle: Default News. - Run
Stache::stores()->each->resetMemoizedState()andapp('stache.indexes')->each->resetMemoizedState(), which is what the service provider does between jobs. - Call
warm()on thetagsstore, reset the memoized state again, and read thetitleindex keys.
Result: 0 keys. Expected: 1. The same file written after an empty query also goes unindexed after clear() then warm(), and after Stache::refresh().
Proposed fix, which makes all three cases return 1 and leaves tests/Stache passing (256 passed, 12 incomplete, 0 failed):
public function warm()
{
+ $this->fileItems = null;
+
$this->shouldCacheFileItems = true;
warm() is the only reader of $fileItems, because getItemsFromFiles() in Store and in ContainerAssetsStore read it only while $shouldCacheFileItems is true. A reset in clear() alone does not cover the worker case. Assigning $fileItems only while caching would be an alternative, and it has not been tested.
Logs
None. No error is raised; the index is silently empty.
Environment
Not applicable: reproduced in a test suite, not on a site.
statamic/cms: v6.43.1 (71387ae6a13659529b135d87b0c5b8eafe2ca7c0)
OS: Windows 11
PHP: 8.4.27
Installation
Other (please explain)
Additional details
Reproduced in a statamic/cms checkout, with a downstream host app on Laravel. The sequence in step 3 is simulated with the provider's own reset calls. A live queue worker or Octane process was not run.
No existing report found on statamic/cms (searched issues and pull requests, open and closed). The open pull request #15856 changes getItemsFromFiles() for an opt-in index build and does not address this.
- Lenguaje dominante
- PHP
- Estrellas
- 4.9k
- Forks
- 647
- Merge medio
- 1 d 45 min
- PR fusionados (30 d)
- 221
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de statamic/cms
-
forms ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
accessibility
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
antlers
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
Nav: link to the site root with an anchor (/#section) gets is_parent on every pagePosiblemente ocupada @duncanmcclean la tomó hoy. Abiertonavigations
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
-
Multiple Choice and Checkboxes no longer offer "Inline", but the default views still use itPosiblemente ocupada @duncanmcclean la tomó hoy. Abiertoforms
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
Todos los issues de statamic/cms
Issues similares
-
sync-en
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
Los mantenedores suelen responder en 1 día
-
Selection on a line without a docblock tag drops trailing characters (data provider attribute)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
vimeo/psalm#15150 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
taskforcesh/bullmq#5238 ·
Los mantenedores suelen responder en 1 día
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects itPosiblemente ocupada @bfs2021 la tomó hoy. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Automattic/jetpack#55517 ·
Los mantenedores suelen responder en 1 día