Skip to content

Commit

Permalink
Query: Rename _prime_post_parents_caches() for clarity.
Browse files Browse the repository at this point in the history
Change the name of `_prime_post_parents_caches()` to `_prime_post_parent_id_caches()` to make it clearer only the parent post ID is cached rather than the entire post parent object.

Follow up to [56763].

Props spacedmonkey, joemcgill, peterwilsoncc.
See #59188.


git-svn-id: https://develop.svn.wordpress.org/trunk@56811 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
peterwilsoncc committed Oct 9, 2023
1 parent 93cc3b1 commit 33b32eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -3191,7 +3191,7 @@ public function get_posts() {

return $this->posts;
} elseif ( 'id=>parent' === $q['fields'] ) {
_prime_post_parents_caches( $post_ids );
_prime_post_parent_id_caches( $post_ids );

/** @var int[] */
$post_parents = wp_cache_get_multiple( $post_ids, 'post_parent' );
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -7797,15 +7797,15 @@ function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache
}

/**
* Prime post parent caches.
* Prime the cache containing the parent ID of various post objects.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @since 6.4.0
*
* @param int[] $ids ID list.
*/
function _prime_post_parents_caches( array $ids ) {
function _prime_post_parent_id_caches( array $ids ) {
global $wpdb;

$non_cached_ids = _get_non_cached_ids( $ids, 'post_parent' );
Expand Down
32 changes: 16 additions & 16 deletions tests/phpunit/tests/post/primePostParentsCaches.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php
/**
* Test `_prime_post_parents_caches()`.
* Test `_prime_post_parent_id_caches()`.
*
* @package WordPress
*/

/**
* Test class for `_prime_post_parents_caches()`.
* Test class for `_prime_post_parent_id_caches()`.
*
* @group post
* @group cache
*
* @covers ::_prime_post_parents_caches
* @covers ::_prime_post_parent_id_caches
*/
class Tests_Post_PrimePostParentsCaches extends WP_UnitTestCase {
class Tests_Post_PrimePostParentIdCaches extends WP_UnitTestCase {

/**
* Post IDs.
Expand All @@ -34,11 +34,11 @@ public static function wpSetupBeforeClass( WP_UnitTest_Factory $factory ) {
/**
* @ticket 59188
*/
public function test_prime_post_parents_caches() {
public function test_prime_post_parent_id_caches() {
$post_id = self::$posts[0];

$before_num_queries = get_num_queries();
_prime_post_parents_caches( array( $post_id ) );
_prime_post_parent_id_caches( array( $post_id ) );
$num_queries = get_num_queries() - $before_num_queries;

$this->assertSame( 1, $num_queries, 'Unexpected number of queries.' );
Expand All @@ -48,9 +48,9 @@ public function test_prime_post_parents_caches() {
/**
* @ticket 59188
*/
public function test_prime_post_parents_caches_multiple() {
public function test_prime_post_parent_id_caches_multiple() {
$before_num_queries = get_num_queries();
_prime_post_parents_caches( self::$posts );
_prime_post_parent_id_caches( self::$posts );
$num_queries = get_num_queries() - $before_num_queries;

$this->assertSame( 1, $num_queries, 'Unexpected number of queries.' );
Expand All @@ -60,10 +60,10 @@ public function test_prime_post_parents_caches_multiple() {
/**
* @ticket 59188
*/
public function test_prime_post_parents_caches_multiple_runs() {
_prime_post_parents_caches( self::$posts );
public function test_prime_post_parent_id_caches_multiple_runs() {
_prime_post_parent_id_caches( self::$posts );
$before_num_queries = get_num_queries();
_prime_post_parents_caches( self::$posts );
_prime_post_parent_id_caches( self::$posts );
$num_queries = get_num_queries() - $before_num_queries;

$this->assertSame( 0, $num_queries, 'Unexpected number of queries.' );
Expand All @@ -72,15 +72,15 @@ public function test_prime_post_parents_caches_multiple_runs() {
/**
* @ticket 59188
*/
public function test_prime_post_parents_caches_update() {
public function test_prime_post_parent_id_caches_update() {
$page_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_parent' => self::$posts[0],
)
);
$before_num_queries = get_num_queries();
_prime_post_parents_caches( array( $page_id ) );
_prime_post_parent_id_caches( array( $page_id ) );
$num_queries = get_num_queries() - $before_num_queries;

$this->assertSame( 1, $num_queries, 'Unexpected number of queries on first run' );
Expand All @@ -94,7 +94,7 @@ public function test_prime_post_parents_caches_update() {
);

$before_num_queries = get_num_queries();
_prime_post_parents_caches( array( $page_id ) );
_prime_post_parent_id_caches( array( $page_id ) );
$num_queries = get_num_queries() - $before_num_queries;

$this->assertSame( 1, $num_queries, 'Unexpected number of queries on second run' );
Expand All @@ -104,7 +104,7 @@ public function test_prime_post_parents_caches_update() {
/**
* @ticket 59188
*/
public function test_prime_post_parents_caches_delete() {
public function test_prime_post_parent_id_caches_delete() {
$parent_page_id = self::factory()->post->create(
array(
'post_type' => 'page',
Expand All @@ -117,7 +117,7 @@ public function test_prime_post_parents_caches_delete() {
)
);
$before_num_queries = get_num_queries();
_prime_post_parents_caches( array( $page_id ) );
_prime_post_parent_id_caches( array( $page_id ) );
$num_queries = get_num_queries() - $before_num_queries;

$this->assertSame( 1, $num_queries, 'Unexpected number of queries on first run' );
Expand Down

0 comments on commit 33b32eb

Please sign in to comment.