Posts, Post Types: Set post filter in update_post_cache().

Ensure the post cache is primed with raw sanitized data. This resolves an inconsistency between how posts retrieved via `get_post()` vs `WP_Query` are cached.

This prevents `sanitize_post( $post, 'raw' )` being run multiple times on a cached post. This can happen over 20 times per post on some page loads so avoiding this will provide a noticeable performance boost.

Props Cybr, SergeyBiryukov, peterwilsoncc, hellofromTonya, costdev.
Fixes #50567.


Built from https://develop.svn.wordpress.org/trunk@53042


git-svn-id: http://core.svn.wordpress.org/trunk@52631 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2022-04-01 03:18:05 +00:00
parent 9131d74641
commit dc07d3ca67
3 changed files with 5 additions and 2 deletions

View File

@ -247,7 +247,7 @@ final class WP_Post {
$_post = sanitize_post( $_post, 'raw' );
wp_cache_add( $_post->ID, $_post, 'posts' );
} elseif ( empty( $_post->filter ) ) {
} elseif ( empty( $_post->filter ) || 'raw' !== $_post->filter ) {
$_post = sanitize_post( $_post, 'raw' );
}

View File

@ -7374,6 +7374,9 @@ function update_post_cache( &$posts ) {
$data = array();
foreach ( $posts as $post ) {
if ( empty( $post->filter ) || 'raw' !== $post->filter ) {
$post = sanitize_post( $post, 'raw' );
}
$data[ $post->ID ] = $post;
}
wp_cache_add_multiple( $data, 'posts' );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-53041';
$wp_version = '6.0-alpha-53042';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.