Make WordPress Core


Ignore:
Timestamp:
10/12/2015 03:12:29 PM (9 years ago)
Author:
boonebgorges
Message:

Don't cache WP_Term objects in wp_get_object_cache().

The data stored in the cache should be raw database query results, not
WP_Term objects (which may be modified by plugins, and may contain additional
properties that shouldn't be cached).

If term relationships caches were handled in wp_get_object_terms() - where
a database query takes place - it would be straightforward to cache raw data.
See #34239. Since, in fact, get_the_terms() caches the value it gets from
wp_get_object_terms(), we need a technique that allows us to get raw data
from a WP_Term object. Mirroring WP_User, we introduce a data property
on term objects, which get_the_terms() uses to fetch cacheable term info.

Fixes #34262.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/category-template.php

    r34696 r35032  
    11381138    if ( false === $terms ) {
    11391139        $terms = wp_get_object_terms( $post->ID, $taxonomy );
    1140         wp_cache_add($post->ID, $terms, $taxonomy . '_relationships');
    1141     }
     1140        $to_cache = array();
     1141        foreach ( $terms as $key => $term ) {
     1142            $to_cache[ $key ] = $term->data;
     1143        }
     1144        wp_cache_add( $post->ID, $to_cache, $taxonomy . '_relationships' );
     1145    }
     1146
     1147    $terms = array_map( 'get_term', $terms );
    11421148
    11431149    /**
Note: See TracChangeset for help on using the changeset viewer.