[6.x] Fix Stache index re-entrancy causing null URIs on cold stache#14109
Open
o1y wants to merge 1 commit intostatamic:6.xfrom
Open
[6.x] Fix Stache index re-entrancy causing null URIs on cold stache#14109o1y wants to merge 1 commit intostatamic:6.xfrom
o1y wants to merge 1 commit intostatamic:6.xfrom
Conversation
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.
Fixes statamic/seo-pro#508
Deep Stache internals ahead. Please try to break or optimize this.. I did my best 👀
On a cold stache, building an index calls getItem() for each entry, which hits getCachedItem(). That method then triggers
->resolveIndex('uri')->load()causing re-entrant index loading.The issue: validateTree() sees incomplete indexes, removes all entries from the structure tree, and all URIs become null. The broken index gets cached, poisoning subsequent requests. That's why the sitemap.xml is empty or
Entry::query()->whereNotNull('uri')returns null 🕳️My introduced caching from #14031 also triggers this in single-site setups, since cached items cause
getCachedItem()to be called during index builds.The main change is about tracking nested index loads, instead of storing the currently loading index in a string. ☀️
It seems also possible to just remove the URI blink from getCachedItem() (or just use the base class function), but this would break the performance optimization which was introduced in #9844
If possible, it might be worth backporting this to 5.x? 🤗