Opened 9 years ago
Last modified 2 years ago
#40711 new enhancement
WP_Post:get_instance: Update cache if $_post->filter is empty
| Reported by: | greencp | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Posts, Post Types | Version: | 4.7.4 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: | performance |
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Implements the code from the description.