[6.x] Fix stache:refresh flattening structured collection trees - #15003
Merged
Conversation
Stache::clear() never invalidated the Blink caches that hold a collection's structured tree, so the single-process clear()+warm() inside stache:refresh could serve a stale, unvalidated tree state computed moments earlier. With structure.root: true, this flattens the whole tree and lets the first entry become the site root. Two Blink key patterns were involved: the tree object cached in CollectionStructure::in(), and the validateTree() memo in Tree::tree(), which is content-addressed on the raw tree array but also depends on the mutable result of queryEntries() - so the same cache key can silently go stale as entries are created. Forget both on clear(), mirroring the existing forget already done on tree save/delete. Also drops the now-redundant manual Blink flush from ColdStacheUriTest, since the production code now does it. Fixes statamic#14996 Co-authored-by: Claude Sonnet 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.
Running
php please stache:refreshon a structured collection (structure.root: true) can flatten the tree in the warmed Stache cache: entries end up at the root level and whichever one sorts first becomes the site root, even though the on-disk tree file is untouched. Runningstache:clearthenstache:warmas separate commands is always correct.Stache::clear()never invalidated the Blink caches that hold a collection's structured tree. Sincestache:refreshrunsclear()andwarm()in one process,warm()could see stale, already-computed tree data from before the clear. Two Blink keys were involved:CollectionStructure::in()validateTree()result memoized inTree::tree(), which is content-addressed only on the raw tree array, butvalidateTree()also readsqueryEntries(), so the same cache key can go stale as entries are created without the key itself changingThis PR makes
clear()forget both, mirroring the existing forget already done on tree save/delete (Tree::save()/Tree::delete()).I couldn't reproduce the exact flattening with an explicit, already-ordered tree in an isolated repro, but I found the existing
ColdStacheUriTesthad a manualBlink::flush()worked into its cold-stache simulation specifically to paper over this same gap. I removed that manual flush and confirmed the production fix makes the test pass on its own, which is direct proofStache::clear()was leaving this stale.Fixes #14996
🤖 Generated with Claude Code