Skip to content

Cache get_page_uri_ancestors() to remove per-render ancestor query (v…#134

Open
DannyCrews wants to merge 1 commit into
masterfrom
fix/cache-page-uri-ancestors
Open

Cache get_page_uri_ancestors() to remove per-render ancestor query (v…#134
DannyCrews wants to merge 1 commit into
masterfrom
fix/cache-page-uri-ancestors

Conversation

@DannyCrews

Copy link
Copy Markdown
Member

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_ancestors function are now cached, significantly reducing unnecessary database queries during front-end renders, especially during site crawls. This change mirrors the persistent caching implemented for load_sections in the previous release, improving performance and scalability.

Caching improvements:

  • The get_page_uri_ancestors function in composer-includes/bu-navigation-core-widget/src/data-get-urls.php now caches ancestor lookup results in the Redis-backed, site-scoped bu-navigation cache. The cache is version-stamped on the core posts' last_changed value 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:

  • Bumped plugin version to 1.3.7 in bu-navigation.php, readme.md, and readme.txt. [1] [2] [3] [4]
  • Updated changelog in readme.md and readme.txt to 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 !== $cached check caches empty-ancestor results (top-level posts) too. Permalinks render identically; slug renames and reparents invalidate correctly via last_changed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread composer-includes/bu-navigation-core-widget/src/data-get-urls.php Outdated
Comment thread composer-includes/bu-navigation-core-widget/src/data-get-urls.php
…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.
@DannyCrews DannyCrews force-pushed the fix/cache-page-uri-ancestors branch from 6e07b0b to 55e4833 Compare June 23, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants