Repository navigation
[6.x] Keep which indexes are used when the Stache is cleared - #15897
Merged
jasonvarga merged 2 commits intoNov 18, 2026
Merged
jasonvarga merged 2 commits into
jasonvarga merged 2 commits into
Conversation
This was referenced Nov 23, 2026
joshdaugherty
added a commit
to UAMS-Web/aether-wordpress-importer
that referenced
this pull request
Nov 24, 2026
…finds its terms under `statamic/cms` 6.43 (#619) Closes #618. Under `statamic/cms` 6.43.1 the flat term pass could not find the terms it had just saved, so a re-import created terms it should have updated and numbered additional terms wrongly. The term store's rebuild now reads the terms from disk before it warms, which works under 6.42.0 and 6.43.1 alike. ## Root cause - `Statamic\Stache\Stores\Store::getItemsFromFiles()` keeps the items its last read returned in `$fileItems`, whether or not a warm is running, and `clear()` does not drop them. `warm()` reuses that value when it is set, and an empty collection counts as set. - The pass's preload query runs before any term is saved, so it leaves an empty collection there. [`rebuildTermStoreFromDisk()`](https://github.com/UAMS-Web/aether-wordpress-importer/blob/618-flat-terms-after-rebuild/src/Services/WordPressImport/Entries/Concerns/PersistsStoredTaxonomyTerms.php) then ran `clear()` and `warm()`, and the warm built every index it builds from that empty collection. - Before 6.43 the warm built only the default indexes, so the `title` index the term query reads was built later, on first use, from disk. statamic/cms#15897 (`v6.43.0`) keeps the record of used indexes through `clear()`, so the warm builds `title` too, and builds it empty. - Measured with a probe test on 6.42.0 with the 6.43 `clear()` change applied: `$fileItems` holds 0 items after the preload; after the pass the path index lists `default::default_news` while the `title` index and its cache are `[]` and `whereTaxonomy('tags')->count()` is 0. Setting `$fileItems` to null before `clear()` and `warm()` gives a count of 1. The defect is Statamic's: the stale read is there in 6.42.0 too, and 6.43.0 is what makes a warm consume it. Without this package's code: on an empty taxonomy, a query by title, then a term file written to disk, then `clear()` and `warm()` (or `Stache::refresh()`), leaves the term unfindable under 6.43.1 (count 0) and findable under 6.42.0 (count 1). The upstream report is drafted separately, for approval before it is posted. ## Fix Between `clear()` and `warm()`, `rebuildTermStoreFromDisk()` calls `getItemsFromFiles()`. Outside a warm it always reads afresh, so it replaces the stale collection, and the warm reuses what it read, so the store's files are read once, as before. It uses only public methods, behind the same `method_exists()` guard as `clear()` and `warm()`. ## Verification - [`FlatTermReimportTest`](https://github.com/UAMS-Web/aether-wordpress-importer/blob/618-flat-terms-after-rebuild/tests/Integration/FlatTermReimportTest.php) gains `finds the terms it saved straight after the pass, when the store warms its title index`. It reads the terms with no second rebuild. Its `title index warmed` case sets `statamic.stache.indexes` to `title`, which makes 6.42 warm the index too, so it reproduces the defect under the version `main` pins. | Installed | Without the fix | With the fix | | --- | --- | --- | | 6.42.0 (`main`'s lock) | 1 of 7 fails (the new `title index warmed` case) | 7 of 7 pass | | 6.42.0 with the two lines statamic/cms#15897 removed | 5 of 5 existing cases fail | 7 of 7 pass | | 6.43.1 (#617's lock, `Store.php` byte-identical to the `v6.43.1` tag, ref `71387ae6`) | 7 of 7 fail | 7 of 7 pass | - The 6.43.1 rows ran in a separate worktree with #617's `composer.json` and `composer.lock` installed. Slot `vendor/` was restored to the `v6.42.0` file and compared with it. - Pre-push: Pint `--test`, Rector `--dry-run`, `composer stan` (no errors) and `check-mutate-ignore-breadth` pass, 0 commits behind `main`. - Host app not run: the changed behavior is asserted by the `Integration` suite, which the gate runs. ## Out of scope - Raising the `statamic/cms` pin, which #617 does. The two touch no common file. #617's `Pest` job goes green once this is on `main`. - Posting the upstream report, which waits on approval. ## Test plan - [x] `FlatTermReimportTest` passes under 6.42.0 and under 6.43.1 with the fix - [x] The new case fails under 6.42.0 without the fix, and every case fails under 6.43.1 without it - [x] Every check on the head passes (56 runs on `7018e09`: 46 success, 10 skipped, 0 failed) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
joshdaugherty
added a commit
to UAMS-Web/aether-wordpress-importer
that referenced
this pull request
Nov 24, 2026
Closes #616. Raises the exact `statamic/cms` pin from `6.42.0` to `6.43.1`, so a release cut from `main` installs beside `uams-web/patches-statamic-cms` v1.2.0, which pins `6.43.1`. No other package moves. ## Files - **edit** [`composer.json`](https://github.com/UAMS-Web/aether-wordpress-importer/blob/616-statamic-cms-6-43-1/composer.json): `require.statamic/cms` `6.42.0` to `6.43.1`. - **edit** [`composer.lock`](https://github.com/UAMS-Web/aether-wordpress-importer/blob/616-statamic-cms-6-43-1/composer.lock): `statamic/cms` `v6.42.0` (`3b28f8c`) to `v6.43.1` (`71387ae`), and the `content-hash`. ## Verification - `composer update statamic/cms` reported `Lock file operations: 0 installs, 1 update, 0 removals`: `Upgrading statamic/cms (v6.42.0 => v6.43.1)`. The lock diff touches only the `statamic/cms` entry and `content-hash`, so `ueberdosis/tiptap-php` stays where it was. The local Composer wrote `plugin-api-version` `2.11.0`; that line was restored to `2.9.0` so the diff carries no tool-version churn. `composer validate --no-check-publish` reports no lock-file errors. - Clean install (`vendor/` removed, `composer install`) exit 0, read to its end: `Patching pestphp/pest-plugin-mutate` lists 15 patch lines and no failure line, against 15 entries in `patches.json`. Reversing all 15 patches in stack order on a copy of the installed package succeeded for 15 of 15, so each one is applied. Every registered patch targets `pestphp/pest-plugin-mutate`, none `statamic/cms`. - Pre-push checks on `9df54f3` (Windows 11): Pint `--test` passed, Rector dry run clean, `node scripts/run-spell.mjs` 135 files 0 issues, `check-mutate-ignore-breadth` no annotation flagged outside the baseline, PHPStan `[OK] No errors`. ### Statamic changes between 6.42.0 and 6.43.1 that touch importer surfaces Read from the upstream release notes for `v6.43.0` and `v6.43.1`. None needs a code change here; each is listed because an import exercises the area: - Prevent term localizations from saving a copy of the non-localizable slug (statamic/cms#15952): term writes in non-default sites. - Rebuild a collection's entries when its sites change (statamic/cms#15906). - Throw an exception when an uploaded file cannot be written to the disk (statamic/cms#15919): an asset write that failed silently now throws. - Do not regenerate asset meta when a value is null (statamic/cms#15978). - Prevent duplicate field handles across imported fieldsets (statamic/cms#15933). - Skip a Stache file that is removed while it is being read (statamic/cms#15903). ## Behavior change found: re-imported flat terms are not found Remote CI on `9df54f3` fails `checks / Pest` on ubuntu-latest and macos-latest: all 5 cases of `tests/Integration/FlatTermReimportTest.php` (13152 passed, 5 failed, 4 skipped). Reproduced on Windows 11: 5 of 5 fail. - **Cause:** statamic/cms#15897 (in `v6.43.0`) stops `Store::clear()` from forgetting which indexes queries have used. Restoring the two removed lines in the installed `src/Stache/Stores/Store.php` makes all 5 cases pass; with the file as shipped, all 5 fail. - **Effect on the importer:** after the flat term pass saves, `rebuildTermStoreFromDisk()` runs `clear()` and `warm()` on the taxonomy's term store. Under `6.43.1`, `Term::whereTaxonomy('tags')->count()` then returns `0` while the term file is on disk and the store's `paths()` lists it; a second `clear()` and `warm()` returns `1`. So a re-import does not see its existing terms: `Overwrite matching terms` creates instead of updating, and `Create an additional term` reuses the base slug. - This pull request stays a draft until that is resolved. ## Companion PRs `UAMS-Web/uams-statamic#1248` waits on a release that carries this pin. Cutting that release is separate and is not part of this pull request. ## Out of scope - Cutting a release. - Moving any other package. ## Test plan - [x] `composer.json` requires `statamic/cms` `6.43.1` and `composer.lock` locks it; the lock diff changes no other package. - [x] Clean install read to its end: 15 of 15 registered patches applied, none failed. - [x] Pre-push checks pass on `9df54f3`, and again on `b7a2661` after the sync with `main` (Pint, PHPStan, Rector, cspell, `check-mutate-ignore-breadth`). - [x] Remote CI green on the head (Linux, Windows, macOS): [`CI` run 45451223175](https://github.com/UAMS-Web/aether-wordpress-importer/actions/runs/45451223175) on `b7a2661` succeeded; 45 checks succeeded and 11 were skipped. The end of each Pest job: ```text ubuntu-latest Tests: 4 skipped, 13172 passed (36771 assertions) Duration: 274.44s macos-latest Tests: 3 skipped, 13173 passed (36827 assertions) Duration: 305.43s windows-latest Tests: 26 skipped, 13150 passed (36619 assertions) Duration: 491.47s ``` Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
stache:clear(and sostache:refresh) forgets which indexes queries have used. The warm that follows then only builds the configured indexes, and the first requests afterwards build the rest themselves, each by loading every item in the store.This keeps the list when a store is cleared, so the next warm builds the indexes the site actually queries.
On a generated site of 11,771 entries (6.42.0,
stache:clearthenstache:warm, then the first request to each page)://articlesThe warm itself took the same time and memory either way (21.4 s, 1.3 GB), as it was already building these indexes before the list had been forgotten once.
With a 256 MB memory limit those first requests fail rather than being slow.
Two things this doesn't do:
cache:clear) still loses the list.Why it was being cleared
It doesn't look like it was to fix anything. The list has been forgotten since
clear()was first written (7241012, "Driver agnostic stache clear"), along with everything else the store had cached.The line next to it, which resets the list on the store itself, came later in #3485 to fix #3476. Clearing had forgotten the cached list but left the one on the store, so the store thought the
pathindex was already recorded and never wrote it back. That showed up in asset containers, which are cleared on every request when the watcher is on.Keeping both doesn't bring that back, as the two can no longer disagree.
Found by @godismyjudge95, who measured this on a much larger site and shared the fix.