Make WordPress Core


Ignore:
Timestamp:
12/16/2014 01:26:19 PM (12 years ago)
Author:
boonebgorges
Message:

Remove caching for get_term_by() calls.

The new cache group scheme causes term invalidation to be overly broad, so
that busting the cache for one term will bust the cache for all terms in the
taxonomy. We'll have another go at more focused use of the 'last_changed'
incrementor in a future release.

Reverts [29915], [30073], [30080], [30108], [30112].
See #21760.

File:
1 edited

Legend:

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

    r30759 r30900  
    13061306        }
    13071307
    1308         $incrementor = wp_cache_get( 'last_changed', 'terms' );
    13091308        if ( is_object($term) && empty($term->filter) ) {
    1310                 wp_cache_add( $term->term_id, $term, $taxonomy . ':terms:' . $incrementor );
    1311                 wp_cache_add( $term->slug, $term->term_id, $taxonomy . ':slugs:' . $incrementor );
    1312                 wp_cache_add( $term->name, $term->term_id, $taxonomy . ':names:' . $incrementor );
     1309                wp_cache_add( $term->term_id, $term, $taxonomy );
    13131310                $_term = $term;
    13141311        } else {
     
    13171314                if ( !$term = (int) $term )
    13181315                        return null;
    1319                 if ( ! $_term = wp_cache_get( $term, $taxonomy . ':terms:' . $incrementor ) ) {
     1316                if ( ! $_term = wp_cache_get( $term, $taxonomy ) ) {
    13201317                        $_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %d LIMIT 1", $taxonomy, $term) );
    13211318                        if ( ! $_term )
    13221319                                return null;
    1323                         wp_cache_add( $term, $_term, $taxonomy . ':terms:' . $incrementor );
    1324                         wp_cache_add( $_term->slug, $term, $taxonomy . ':slugs:' . $incrementor );
    1325                         wp_cache_add( $_term->name, $term, $taxonomy . ':names:' . $incrementor );
     1320                        wp_cache_add( $term, $_term, $taxonomy );
    13261321                }
    13271322        }
     
    13941389                return false;
    13951390
    1396         $cache = false;
    1397         $incrementor = wp_cache_get( 'last_changed', 'terms' );
    13981391        if ( 'slug' == $field ) {
    13991392                $field = 't.slug';
     
    14011394                if ( empty($value) )
    14021395                        return false;
    1403 
    1404                 $term_id = wp_cache_get( $value, $taxonomy . ':slugs:' . $incrementor );
    1405                 if ( $term_id ) {
    1406                         $value = $term_id;
    1407                         $cache = true;
    1408                 }
    14091396        } else if ( 'name' == $field ) {
    14101397                // Assume already escaped
    14111398                $value = wp_unslash($value);
    14121399                $field = 't.name';
    1413                 $term_id = wp_cache_get( $value, $taxonomy . ':names:' . $incrementor  );
    1414                 if ( $term_id ) {
    1415                         $value = $term_id;
    1416                         $cache = true;
    1417                 }
    14181400        } else if ( 'term_taxonomy_id' == $field ) {
    14191401                $value = (int) $value;
    14201402                $field = 'tt.term_taxonomy_id';
    14211403        } else {
    1422                 $cache = true;
    1423         }
    1424 
    1425         if ( $cache ) {
    1426                 $term = get_term( (int) $value, $taxonomy, $output, $filter);
    1427                 if ( is_wp_error( $term ) ) {
     1404                $term = get_term( (int) $value, $taxonomy, $output, $filter );
     1405                if ( is_wp_error( $term ) )
    14281406                        $term = false;
    1429                 }
    1430         } else {
    1431                 $term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value) );
    1432         }
    1433 
    1434         if ( !$term )
     1407                return $term;
     1408        }
     1409
     1410        $term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value ) );
     1411        if ( ! $term )
    14351412                return false;
     1413
     1414        wp_cache_add( $term->term_id, $term, $taxonomy );
    14361415
    14371416        /** This filter is documented in wp-includes/taxonomy.php */
     
    14421421
    14431422        $term = sanitize_term($term, $taxonomy, $filter);
    1444 
    1445         wp_cache_add( $term->term_id, $term, $taxonomy . ':terms:' . $incrementor );
    1446         wp_cache_add( $term->slug, $term->term_id, $taxonomy . ':slugs:' . $incrementor );
    1447         wp_cache_add( $term->name, $term->term_id, $taxonomy . ':names:' . $incrementor );
    14481423
    14491424        if ( $output == OBJECT ) {
     
    36503625 */
    36513626function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {
    3652         global $_wp_suspend_cache_invalidation, $wpdb;
    3653 
    3654         if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
    3655                 return;
    3656         }
     3627        global $wpdb;
    36573628
    36583629        if ( !is_array($ids) )
     
    37933764 */
    37943765function update_term_cache($terms, $taxonomy = '') {
    3795         global $_wp_suspend_cache_invalidation;
    3796 
    3797         if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
    3798                 return;
    3799         }
    3800 
    38013766        foreach ( (array) $terms as $term ) {
    38023767                $term_taxonomy = $taxonomy;
     
    38043769                        $term_taxonomy = $term->taxonomy;
    38053770
    3806                 $incrementor = wp_cache_set( 'last_changed', microtime(), 'terms' );
    3807 
    3808                 wp_cache_add( $term->term_id, $term, $term_taxonomy . ':terms:' . $incrementor );
    3809                 wp_cache_add( $term->slug, $term->term_id, $taxonomy . ':slugs:' . $incrementor );
    3810                 wp_cache_add( $term->name, $term->term_id, $taxonomy . ':names:' . $incrementor );
     3771                wp_cache_add( $term->term_id, $term, $term_taxonomy );
    38113772        }
    38123773}
Note: See TracChangeset for help on using the changeset viewer.