Skip to content

Commit eed6f20

Browse files
committed
Rewrites: Reinstate split the query for random redirects.
Removes the filtering of `split_the_query` to `false` on random post redirects. As sorting queries randomly generates a temporary table, selecting `*` places all data in the temporary table, whereas selecting `ID` only places the post ID in the temporary table. The unsplit query can become inefficient on sites with a relatively few posts (ie, thousands not millions). This removes the function `wp_random_content_split_the_query()` with a hard deprecation as it was not released to a production version of WordPress. Additionally, the following changes have been made to the test suite: * Tests ensuring random redirects are not cached are refactored to avoid the `$this->go_to()` method in the test suite as the helper method flushes the cache, causing the tests to be invalid * Introduces tests covering `WP::handle_random()` specifically * Adds docblocks to each and every test in `Tests_Query_RandomContentRedirect` Developed in WordPress#14809. Follow-up to r63767, r63906, r64402. Props aryanjasala, peterwilsoncc, dhrupo, westonruter. Fixes #64498. git-svn-id: https://develop.svn.wordpress.org/trunk@65042 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 63cd9ce commit eed6f20

4 files changed

Lines changed: 601 additions & 94 deletions

File tree

‎src/wp-includes/default-filters.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@
496496
add_action( 'attachment_updated', 'wp_check_for_changed_dates', 12, 3 );
497497

498498
// Random content redirects, see WP::handle_random().
499-
add_filter( 'split_the_query', 'wp_random_content_split_the_query', 10, 2 );
500499
add_action( 'wp_after_insert_post', 'wp_random_content_flush_rewrite_rules_for_post', 10, 4 );
501500
add_action( 'after_delete_post', 'wp_random_content_flush_rewrite_rules_for_post', 10, 2 );
502501

‎src/wp-includes/query.php‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,27 +1461,6 @@ function wp_random_content_post_limits( $limits, WP_Query $query ): string {
14611461
return (string) $limits;
14621462
}
14631463

1464-
/**
1465-
* Prevents the random content query from being split into multiple database queries.
1466-
*
1467-
* Randomly ordered queries are not cached, so there is no benefit to querying the post
1468-
* IDs separately to the post objects. Disabling the split allows the random post to be
1469-
* retrieved in a single database query.
1470-
*
1471-
* @since 7.2.0
1472-
*
1473-
* @param bool $split_the_query Whether or not to split the query.
1474-
* @param WP_Query $query The WP_Query instance.
1475-
* @return bool Whether or not to split the query.
1476-
*/
1477-
function wp_random_content_split_the_query( $split_the_query, WP_Query $query ): bool {
1478-
if ( wp_is_random_content_query( $query ) ) {
1479-
return false;
1480-
}
1481-
1482-
return (bool) $split_the_query;
1483-
}
1484-
14851464
/**
14861465
* Redirects random content requests to the randomly selected post.
14871466
*

0 commit comments

Comments
 (0)