Store only term IDs in object term relationships caches.

Previously, objects containing all data about a term were stored in each
object's term cache. Besides being wasteful, this approach caused invalidation
issues, as when a modified term count required a flush for all objects
belonging to the term.

Backward compatibility is maintained for plugins that continue to put object
data directly into the `{$taxonomy}_relationships` cache bucket.

Fixes #36814.

git-svn-id: https://develop.svn.wordpress.org/trunk@37573 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2016-05-26 04:49:10 +00:00
parent 8b9bdaccd2
commit 96b71d7d89
5 changed files with 110 additions and 36 deletions
+2 -9
View File
@@ -1187,18 +1187,11 @@ function get_the_terms( $post, $taxonomy ) {
if ( false === $terms ) {
$terms = wp_get_object_terms( $post->ID, $taxonomy );
if ( ! is_wp_error( $terms ) ) {
$to_cache = array();
foreach ( $terms as $key => $term ) {
$to_cache[ $key ] = $term->data;
}
wp_cache_add( $post->ID, $to_cache, $taxonomy . '_relationships' );
$term_ids = wp_list_pluck( $terms, 'term_id' );
wp_cache_add( $post->ID, $term_ids, $taxonomy . '_relationships' );
}
}
if ( ! is_wp_error( $terms ) ) {
$terms = array_map( 'get_term', $terms );
}
/**
* Filters the list of terms attached to the given post.
*