Make WordPress Core


Ignore:
Timestamp:
10/12/2023 11:39:05 PM (9 months ago)
Author:
peterwilsoncc
Message:

Query: Cache post parent IDs in posts group.

Move the cache of post parent IDs from the dedicated group post_parents to posts. This maintains backward compatibility for clearing all post object related data by calling wp_cache_flush_group( 'posts' ).

Post parent IDs are now cached with with the prefix post_parent: in the posts group.

Follow up to [56763].

Props spacedmonkey, joemcgill, peterwilsoncc.
See #59188.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/primePostParentsCaches.php

    r56811 r56925  
    4343
    4444        $this->assertSame( 1, $num_queries, 'Unexpected number of queries.' );
    45         $this->assertSameSets( array( 0 ), wp_cache_get_multiple( array( $post_id ), 'post_parent' ), 'Array of parent ids' );
     45        $this->assertSameSets( array( 0 ), wp_cache_get_multiple( array( "post_parent:{$post_id}" ), 'posts' ), 'Array of parent ids' );
    4646    }
    4747
     
    5454        $num_queries = get_num_queries() - $before_num_queries;
    5555
     56        $cache_keys = array_map(
     57            function ( $post_id ) {
     58                return "post_parent:{$post_id}";
     59            },
     60            self::$posts
     61        );
     62
    5663        $this->assertSame( 1, $num_queries, 'Unexpected number of queries.' );
    57         $this->assertSameSets( array( 0, 0, 0 ), wp_cache_get_multiple( self::$posts, 'post_parent' ), 'Array of parent ids' );
     64        $this->assertSameSets( array( 0, 0, 0 ), wp_cache_get_multiple( $cache_keys, 'posts' ), 'Array of parent ids' );
    5865    }
    5966
     
    8592
    8693        $this->assertSame( 1, $num_queries, 'Unexpected number of queries on first run' );
    87         $this->assertSameSets( array( self::$posts[0] ), wp_cache_get_multiple( array( $page_id ), 'post_parent' ), 'Array of parent ids with post 0 as parent' );
     94        $this->assertSameSets( array( self::$posts[0] ), wp_cache_get_multiple( array( "post_parent:{$page_id}" ), 'posts' ), 'Array of parent ids with post 0 as parent' );
    8895
    8996        wp_update_post(
     
    99106
    100107        $this->assertSame( 1, $num_queries, 'Unexpected number of queries on second run' );
    101         $this->assertSameSets( array( self::$posts[1] ), wp_cache_get_multiple( array( $page_id ), 'post_parent' ), 'Array of parent ids with post 1 as parent' );
     108        $this->assertSameSets( array( self::$posts[1] ), wp_cache_get_multiple( array( "post_parent:{$page_id}" ), 'posts' ), 'Array of parent ids with post 1 as parent' );
    102109    }
    103110
     
    122129
    123130        $this->assertSame( 1, $num_queries, 'Unexpected number of queries on first run' );
    124         $this->assertSameSets( array( $parent_page_id ), wp_cache_get_multiple( array( $page_id ), 'post_parent' ), 'Array of parent ids with post 0 as parent' );
     131        $this->assertSameSets( array( $parent_page_id ), wp_cache_get_multiple( array( "post_parent:{$page_id}" ), 'posts' ), 'Array of parent ids with post 0 as parent' );
    125132
    126133        wp_delete_post( $parent_page_id, true );
    127134
    128135        $this->assertSame( 1, $num_queries, 'Unexpected number of queries on second run' );
    129         $this->assertSameSets( array( false ), wp_cache_get_multiple( array( $page_id ), 'post_parent' ), 'Array of parent ids with false values' );
     136        $this->assertSameSets( array( false ), wp_cache_get_multiple( array( "post_parent:{$page_id}" ), 'posts' ), 'Array of parent ids with false values' );
    130137    }
    131138}
Note: See TracChangeset for help on using the changeset viewer.