Repository navigation
WIP: Use a 50 post pool for selecting random redirect. - #16044
Closed
peterwilsoncc wants to merge 3 commits into
Closed
peterwilsoncc wants to merge 3 commits into
peterwilsoncc wants to merge 3 commits into
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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.
Vibe coded: not to be merged in its current state
Explores caching a pool of 50 randomly ordered posts for random content redirects, so that the database only orders every eligible post when the pool isn't cached.
ORDER BY RAND() LIMIT 0, 50rather than a single post. Selecting 50 posts costs about the same as selecting one, as the database orders every eligible post either way.wp_random_content_posts_pre_query()function on theposts_pre_queryfilter caches the pool of IDs in thepost-queriesgroup for an hour, salted with the postslast_changedvalue. Each request selects a post from the pool withwp_rand().idsquery, so only the selected post is loaded. The callback then sets thefieldsquery variable toall, so the main query's post is set.WP_Query.Known issues
fieldsquery variable inside the filter is a workaround that relies onWP_Queryreading it afterposts_pre_queryruns.Trac ticket: https://core.trac.wordpress.org/ticket/66654
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Vibe coded POC. Pushed as a WIP draft to share with @aaronjorbin, not a merge candidate.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.