feat(multisite): cache the network recent-posts aggregation (#115)#142
Merged
Conversation
Wrap a genuinely expensive cross-site query in a site-transient cache with invalidation. - get_recent_network_posts() switches into every network site and runs a query per site, then merges and date-sorts the results — real work that scales with the number of sites. The merged list is cached in a site (network) transient (set_site_transient, 10-minute TTL); a cache hit returns immediately with no switch_to_blog() loop. - Invalidation: save_post (skipping autosaves and revisions) and deleted_post clear the transient, so any real create/update/delete on any site rebuilds the aggregate. - Added a flavian_recent_network_posts shortcode as the consumer. Verified with the repo's WPCS config (WordPress-Extra + Docs): 0 errors, 0 warnings. Redence-Proof-Token: RDNC-K8RKWK Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Closes #115.
Real caching + invalidation on a genuinely expensive operation, using
get_site_transient/set_site_transient.The expensive operation
get_recent_network_posts()aggregates recent published posts across the wholenetwork — it
switch_to_blog()es into every site and runs aget_posts()query per site, then merges and date-sorts the results. Cost scales with the
number of sites, so it's a real candidate for caching.
Caching
The merged, sorted list is stored in a site (network) transient
(
set_site_transient, 10-minute TTL). On a cache hit it returns immediately fromget_site_transientwith no per-site switching or querying.Invalidation
save_post— clears the transient on any real create/update (autosaves andrevisions are skipped so routine editor traffic doesn't churn the cache).
deleted_post— clears it when a post is removed.Any of these on any network site rebuilds the aggregate on the next read.
Consumer
A
flavian_recent_network_postsshortcode (mirroring the existingflavian_network_sitesone) renders the cached list, so the cache path isactually exercised.
Checks
WPCS (WordPress-Extra + WordPress-Docs) via the repo config: 0 errors, 0
warnings (phpcbf reported no violations). One file changed
(
mu-plugins/flavian-multisite.php).(The Redence Caching proof token is in the commit message per the issue.)
🤖 Generated with Claude Code