Make WordPress Core

Changeset 53042


Ignore:
Timestamp:
04/01/2022 03:16:33 AM (2 years ago)
Author:
peterwilsoncc
Message:

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.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-post.php

    r49544 r53042  
    248248            $_post = sanitize_post( $_post, 'raw' );
    249249            wp_cache_add( $_post->ID, $_post, 'posts' );
    250         } elseif ( empty( $_post->filter ) ) {
     250        } elseif ( empty( $_post->filter ) || 'raw' !== $_post->filter ) {
    251251            $_post = sanitize_post( $_post, 'raw' );
    252252        }
  • trunk/src/wp-includes/post.php

    r52978 r53042  
    73757375    $data = array();
    73767376    foreach ( $posts as $post ) {
     7377        if ( empty( $post->filter ) || 'raw' !== $post->filter ) {
     7378            $post = sanitize_post( $post, 'raw' );
     7379        }
    73777380        $data[ $post->ID ] = $post;
    73787381    }
Note: See TracChangeset for help on using the changeset viewer.