Make WordPress Core

Changeset 30073


Ignore:
Timestamp:
10/28/2014 09:04:52 PM (12 years ago)
Author:
wonderboymusic
Message:

Adjust caching for get_term_by() calls:

  • Remove md5 hashes for term name cache keys
  • Remove the namespace for the keys for names and slugs and add them to the group names
  • Remove wp_get_last_changed(), which @nacin hated


Props tollmanz.
Fixes #21760.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

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

    r30058 r30073  
    47434743        return (bool) $var;
    47444744}
    4745 
    4746 /**
    4747  * Helper function to retrieve an incrementer identified by $group
    4748  *
    4749  * @since 4.1.0
    4750  *
    4751  * @param string $group The cache group for the incrementer.
    4752  * @param bool $force Whether or not to generate a new incrementor.
    4753  * @return int The timestamp representing 'last_changed'.
    4754  */
    4755 function wp_get_last_changed( $group, $force = false ) {
    4756         $last_changed = wp_cache_get( 'last_changed', $group );
    4757         if ( ! $last_changed || true === $force ) {
    4758                 $last_changed = microtime();
    4759                 wp_cache_set( 'last_changed', $last_changed, $group );
    4760         }
    4761         return $last_changed;
    4762 }
  • trunk/src/wp-includes/taxonomy.php

    r30052 r30073  
    12921292        }
    12931293
    1294         $group = $taxonomy . ':' . wp_get_last_changed( 'terms' );
     1294        $incrementor = wp_cache_get( 'last_changed', 'terms' );
    12951295        if ( is_object($term) && empty($term->filter) ) {
    1296                 wp_cache_add( $term->term_id, $term, $taxonomy );
    1297                 wp_cache_add( "slug:{$term->slug}", $term->term_id, $group );
    1298                 wp_cache_add( "name:" . md5( $term->name ), $term->term_id, $group );
     1296                wp_cache_add( $term->term_id, $term, $taxonomy . ':terms:' . $incrementor );
     1297                wp_cache_add( $term->slug, $term->term_id, $taxonomy . ':slugs:' . $incrementor );
     1298                wp_cache_add( $term->name, $term->term_id, $taxonomy . ':names:' . $incrementor );
    12991299                $_term = $term;
    13001300        } else {
     
    13071307                        if ( ! $_term )
    13081308                                return null;
    1309                         wp_cache_add( $term, $_term, $taxonomy );
    1310                         wp_cache_add( "slug:{$_term->slug}", $term, $group );
    1311                         wp_cache_add( "name:" . md5( $_term->name ), $term, $group );
     1309                        wp_cache_add( $term, $_term, $taxonomy . ':terms:' . $incrementor );
     1310                        wp_cache_add( $_term->slug, $term, $taxonomy . ':slugs:' . $incrementor );
     1311                        wp_cache_add( $_term->name, $term, $taxonomy . ':names:' . $incrementor );
    13121312                }
    13131313        }
     
    13821382
    13831383        $cache = false;
    1384         $group = $taxonomy . ':' . wp_get_last_changed( 'terms' );
     1384        $incrementor = wp_cache_get( 'last_changed', 'terms' );
    13851385        if ( 'slug' == $field ) {
    13861386                $field = 't.slug';
     
    13891389                        return false;
    13901390
    1391                 $term_id = wp_cache_get( "slug:{$value}", $group );
     1391                $term_id = wp_cache_get( $value, $taxonomy . ':slugs:' . $incrementor );
    13921392                if ( $term_id ) {
    13931393                        $value = $term_id;
     
    13981398                $value = wp_unslash($value);
    13991399                $field = 't.name';
    1400                 $term_id = wp_cache_get( "name:" . md5( $value ), $group );
     1400                $term_id = wp_cache_get( $value, $taxonomy . ':names:' . $incrementor );
    14011401                if ( $term_id ) {
    14021402                        $value = $term_id;
     
    14301430        $term = sanitize_term($term, $taxonomy, $filter);
    14311431
    1432         wp_cache_add( $term->term_id, $term, $taxonomy );
    1433         wp_cache_add( "slug:{$term->slug}", $term->term_id, $group );
    1434         wp_cache_add( "name:" . md5( $term->name ), $term->term_id, $group );
     1432        wp_cache_add( $term->term_id, $term, $taxonomy . ':terms:' . $incrementor );
     1433        wp_cache_add( $term->slug, $term->term_id, $taxonomy . ':slugs:' . $incrementor );
     1434        wp_cache_add( $term->name, $term->term_id, $taxonomy . ':names:' . $incrementor );
    14351435
    14361436        if ( $output == OBJECT ) {
     
    36713671        }
    36723672
    3673         wp_get_last_changed( 'terms', true );
     3673        wp_cache_set( 'last_changed', microtime(), 'terms' );
    36743674}
    36753675
     
    37773777                        $term_taxonomy = $term->taxonomy;
    37783778
    3779                 wp_cache_add( $term->term_id, $term, $term_taxonomy );
    3780                 $group = $term_taxonomy . ':' . wp_get_last_changed( 'terms', true );
    3781                 wp_cache_add( "slug:{$term->slug}", $term->term_id, $group );
    3782                 wp_cache_add( "name:" . md5( $term->name ), $term->term_id, $group );
     3779                $incrementor = wp_cache_set( 'last_changed', microtime(), 'terms' );
     3780
     3781                wp_cache_add( $term->term_id, $term, $term_taxonomy . ':terms:' . $incrementor );
     3782                wp_cache_add( $term->slug, $term->term_id, $taxonomy . ':slugs:' . $incrementor );
     3783                wp_cache_add( $term->name, $term->term_id, $taxonomy . ':names:' . $incrementor );
    37833784        }
    37843785}
Note: See TracChangeset for help on using the changeset viewer.