Opened 7 years ago
Last modified 4 months ago
#40711 new enhancement
WP_Post:get_instance: Update cache if $_post->filter is empty
Reported by: | greencp | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.7.4 |
Component: | Posts, Post Types | Keywords: | has-patch |
Focuses: | performance | Cc: |
Description
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
} elseif ( empty( $_post->filter ) ) {
$_post = sanitize_post( $_post, 'raw' );
}
add wp_cache_replace
} elseif ( empty( $_post->filter ) ) {
$_post = sanitize_post( $_post, 'raw' );
wp_cache_replace( $_post->ID, $_post, 'posts' );
}
This significantly reduces unnecessary calls to sanitize_post.
Attachments (1)
Change History (3)
Note: See
TracTickets for help on using
tickets.
Implements the code from the description.