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/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        }
Note: See TracChangeset for help on using the changeset viewer.