[wp-trac] [WordPress Trac] #40711: WP_Post:get_instance: Update cache if $_post->filter is empty
WordPress Trac
noreply at wordpress.org
Wed May 10 09:52:08 UTC 2017
#40711: WP_Post:get_instance: Update cache if $_post->filter is empty
-------------------------------+-----------------------------
Reporter: greencp | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: 4.7.4
Severity: normal | Keywords:
Focuses: performance |
-------------------------------+-----------------------------
WP_Post::get_instance always returns raw filtered posts. At least in my
tests it gets many hits where a post is already cached, but not filtered.
For each hit it calls sanitize_post again.
To improve performance, if a cached post isn't filtered, update the cache
after calling sanitize_post.
class-wp-post.php, line 228:
Instead of
{{{#!php
} elseif ( empty( $_post->filter ) ) {
$_post = sanitize_post( $_post, 'raw' );
}
}}}
add wp_cache_replace
{{{#!php
} elseif ( empty( $_post->filter ) ) {
$_post = sanitize_post( $_post, 'raw' );
wp_cache_replace( $_post->ID, $_post, 'posts' );
}
}}}
This significantly reduces unnecessary calls to sanitize_post.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40711>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list