Make WordPress Core


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.