Cache get_page_uri_ancestors() to remove per-render ancestor query (v…#134
Open
DannyCrews wants to merge 1 commit into
Open
Cache get_page_uri_ancestors() to remove per-render ancestor query (v…#134DannyCrews wants to merge 1 commit into
DannyCrews wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR bumps the BU Navigation plugin to 1.3.7 and introduces persistent object caching for get_page_uri_ancestors() to eliminate repeated ancestor-chain database queries during front-end renders (notably during crawler traffic).
Changes:
- Add Redis-backed, site-scoped, version-stamped persistent caching for
get_page_uri_ancestors()with a TTL backstop. - Bump plugin version references to 1.3.7.
- Update changelogs to document the new ancestor-lookup caching behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| composer-includes/bu-navigation-core-widget/src/data-get-urls.php | Adds persistent caching to get_page_uri_ancestors() to reduce per-render ancestor queries. |
| bu-navigation.php | Bumps plugin header version and BU_Navigation_Plugin::VERSION to 1.3.7. |
| readme.md | Updates stable tag and adds 1.3.7 changelog entry describing the caching change. |
| readme.txt | Updates stable tag and adds 1.3.7 changelog entry describing the caching change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…1.3.7) get_page_uri_ancestors() resolves a post's ancestor chain when building permalinks and is the only caller of the uncached get_nav_posts() query on the missing-ancestor path. It ran once per missing-ancestor chain on nearly every front-end render, re-issuing the raw posts query on each request -- the dominant source of wp_posts read amplification during crawls. #133 made load_sections() persistent but left this query uncached, so it continued to fire on every warm request (verified: warm renders still ran the ancestor query under 1.3.6). Cache the result in the site-scoped, version-stamped 'bu-navigation' group, mirroring the 1.3.6 load_sections() pattern: keyed on (blog_id, post ID, post_type) + posts 'last_changed' (bumped by clean_post_cache on any post edit), with a DAY_IN_SECONDS TTL backstop. A strict `false !== $cached` check caches empty-ancestor results (top-level posts) too. Permalinks render identically; slug renames and reparents invalidate correctly via last_changed.
6e07b0b to
55e4833
Compare
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.
This pull request updates the plugin to version 1.3.7 and introduces persistent caching for the per-post ancestor lookup in the navigation system. The main improvement is that the results of the
get_page_uri_ancestorsfunction are now cached, significantly reducing unnecessary database queries during front-end renders, especially during site crawls. This change mirrors the persistent caching implemented forload_sectionsin the previous release, improving performance and scalability.Caching improvements:
get_page_uri_ancestorsfunction incomposer-includes/bu-navigation-core-widget/src/data-get-urls.phpnow caches ancestor lookup results in the Redis-backed, site-scopedbu-navigationcache. The cache is version-stamped on the core posts'last_changedvalue and has a one-day TTL as a fallback. This prevents repeated, expensive database queries on every front-end render and ensures cache invalidation on post edits. [1] [2]Version and documentation updates:
bu-navigation.php,readme.md, andreadme.txt. [1] [2] [3] [4]readme.mdandreadme.txtto document the new persistent caching for ancestor lookups. [1] [2]…1.3.7)get_page_uri_ancestors() resolves a post's ancestor chain when building permalinks and is the only caller of the uncached get_nav_posts() query on the missing-ancestor path. It ran once per missing-ancestor chain on nearly every front-end render, re-issuing the raw posts query on each request -- the dominant source of wp_posts read amplification during crawls.
#133 made load_sections() persistent but left this query uncached, so it continued to fire on every warm request (verified: warm renders still ran the ancestor query under 1.3.6).
Cache the result in the site-scoped, version-stamped 'bu-navigation' group, mirroring the 1.3.6 load_sections() pattern: keyed on (blog_id, post ID, post_type) + posts 'last_changed' (bumped by clean_post_cache on any post edit), with a DAY_IN_SECONDS TTL backstop. A strict
false !== $cachedcheck caches empty-ancestor results (top-level posts) too. Permalinks render identically; slug renames and reparents invalidate correctly via last_changed.