WordPress.org

Make WordPress Core

Ticket #21760: 21760.12.diff

File 21760.12.diff, 5.1 KB (added by tollmanz, 6 years ago)
  • src/wp-includes/functions.php

    diff --git src/wp-includes/functions.php src/wp-includes/functions.php
    index ab34f2e..c19e0dd 100644
    function wp_validate_boolean( $var ) { 
    46294629
    46304630        return (bool) $var;
    46314631}
    4632 
    4633 /**
    4634  * Helper function to retrieve an incrementer identified by $group
    4635  *
    4636  * @since 4.1.0
    4637  *
    4638  * @param string $group The cache group for the incrementer.
    4639  * @param bool $force Whether or not to generate a new incrementor.
    4640  * @return int The timestamp representing 'last_changed'.
    4641  */
    4642 function wp_get_last_changed( $group, $force = false ) {
    4643         $last_changed = wp_cache_get( 'last_changed', $group );
    4644         if ( ! $last_changed || true === $force ) {
    4645                 $last_changed = microtime();
    4646                 wp_cache_set( 'last_changed', $last_changed, $group );
    4647         }
    4648         return $last_changed;
    4649 }
    4650  No newline at end of file
  • src/wp-includes/taxonomy.php

    diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
    index b8261df..82280ff 100644
    function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { 
    12911291                return $error;
    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 {
    13011301                if ( is_object($term) )
    function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { 
    13061306                        $_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) );
    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        }
    13141314
    function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw 
    13811381                return false;
    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';
    13871387                $value = sanitize_title($value);
    13881388                if ( empty($value) )
    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;
    13941394                        $cache = true;
    function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw 
    13971397                // Assume already escaped
    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;
    14031403                        $cache = true;
    function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw 
    14291429
    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 ) {
    14371437                return $term;
    function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { 
    36623662                do_action( 'clean_term_cache', $ids, $taxonomy );
    36633663        }
    36643664
    3665         wp_get_last_changed( 'terms', true );
     3665        wp_cache_set( 'last_changed', microtime(), 'terms' );
    36663666}
    36673667
    36683668/**
    function update_term_cache($terms, $taxonomy = '') { 
    37683768                if ( empty($term_taxonomy) )
    37693769                        $term_taxonomy = $term->taxonomy;
    37703770
    3771                 wp_cache_add( $term->term_id, $term, $term_taxonomy );
    3772                 $group = $term_taxonomy . ':' . wp_get_last_changed( 'terms', true );
    3773                 wp_cache_add( "slug:{$term->slug}", $term->term_id, $group );
    3774                 wp_cache_add( "name:" . md5( $term->name ), $term->term_id, $group );
     3771                $incrementor = wp_cache_set( 'last_changed', microtime(), 'terms' );
     3772
     3773                wp_cache_add( $term->term_id, $term, $term_taxonomy . ':terms:' . $incrementor );
     3774                wp_cache_add( $term->slug, $term->term_id, $taxonomy . ':slugs:' . $incrementor );
     3775                wp_cache_add( $term->name, $term->term_id, $taxonomy . ':names:' . $incrementor );
    37753776        }
    37763777}
    37773778