mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-22 16:21:26 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@30073 git-svn-id: http://core.svn.wordpress.org/trunk@30073 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9d0e0a00f9
commit
315612a96b
@ -4742,21 +4742,3 @@ function wp_validate_boolean( $var ) {
|
||||
|
||||
return (bool) $var;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to retrieve an incrementer identified by $group
|
||||
*
|
||||
* @since 4.1.0
|
||||
*
|
||||
* @param string $group The cache group for the incrementer.
|
||||
* @param bool $force Whether or not to generate a new incrementor.
|
||||
* @return int The timestamp representing 'last_changed'.
|
||||
*/
|
||||
function wp_get_last_changed( $group, $force = false ) {
|
||||
$last_changed = wp_cache_get( 'last_changed', $group );
|
||||
if ( ! $last_changed || true === $force ) {
|
||||
$last_changed = microtime();
|
||||
wp_cache_set( 'last_changed', $last_changed, $group );
|
||||
}
|
||||
return $last_changed;
|
||||
}
|
@ -1291,11 +1291,11 @@ function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') {
|
||||
return $error;
|
||||
}
|
||||
|
||||
$group = $taxonomy . ':' . wp_get_last_changed( 'terms' );
|
||||
$incrementor = wp_cache_get( 'last_changed', 'terms' );
|
||||
if ( is_object($term) && empty($term->filter) ) {
|
||||
wp_cache_add( $term->term_id, $term, $taxonomy );
|
||||
wp_cache_add( "slug:{$term->slug}", $term->term_id, $group );
|
||||
wp_cache_add( "name:" . md5( $term->name ), $term->term_id, $group );
|
||||
wp_cache_add( $term->term_id, $term, $taxonomy . ':terms:' . $incrementor );
|
||||
wp_cache_add( $term->slug, $term->term_id, $taxonomy . ':slugs:' . $incrementor );
|
||||
wp_cache_add( $term->name, $term->term_id, $taxonomy . ':names:' . $incrementor );
|
||||
$_term = $term;
|
||||
} else {
|
||||
if ( is_object($term) )
|
||||
@ -1306,9 +1306,9 @@ function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') {
|
||||
$_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) );
|
||||
if ( ! $_term )
|
||||
return null;
|
||||
wp_cache_add( $term, $_term, $taxonomy );
|
||||
wp_cache_add( "slug:{$_term->slug}", $term, $group );
|
||||
wp_cache_add( "name:" . md5( $_term->name ), $term, $group );
|
||||
wp_cache_add( $term, $_term, $taxonomy . ':terms:' . $incrementor );
|
||||
wp_cache_add( $_term->slug, $term, $taxonomy . ':slugs:' . $incrementor );
|
||||
wp_cache_add( $_term->name, $term, $taxonomy . ':names:' . $incrementor );
|
||||
}
|
||||
}
|
||||
|
||||
@ -1381,14 +1381,14 @@ function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw
|
||||
return false;
|
||||
|
||||
$cache = false;
|
||||
$group = $taxonomy . ':' . wp_get_last_changed( 'terms' );
|
||||
$incrementor = wp_cache_get( 'last_changed', 'terms' );
|
||||
if ( 'slug' == $field ) {
|
||||
$field = 't.slug';
|
||||
$value = sanitize_title($value);
|
||||
if ( empty($value) )
|
||||
return false;
|
||||
|
||||
$term_id = wp_cache_get( "slug:{$value}", $group );
|
||||
$term_id = wp_cache_get( $value, $taxonomy . ':slugs:' . $incrementor );
|
||||
if ( $term_id ) {
|
||||
$value = $term_id;
|
||||
$cache = true;
|
||||
@ -1397,7 +1397,7 @@ function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw
|
||||
// Assume already escaped
|
||||
$value = wp_unslash($value);
|
||||
$field = 't.name';
|
||||
$term_id = wp_cache_get( "name:" . md5( $value ), $group );
|
||||
$term_id = wp_cache_get( $value, $taxonomy . ':names:' . $incrementor );
|
||||
if ( $term_id ) {
|
||||
$value = $term_id;
|
||||
$cache = true;
|
||||
@ -1429,9 +1429,9 @@ function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw
|
||||
|
||||
$term = sanitize_term($term, $taxonomy, $filter);
|
||||
|
||||
wp_cache_add( $term->term_id, $term, $taxonomy );
|
||||
wp_cache_add( "slug:{$term->slug}", $term->term_id, $group );
|
||||
wp_cache_add( "name:" . md5( $term->name ), $term->term_id, $group );
|
||||
wp_cache_add( $term->term_id, $term, $taxonomy . ':terms:' . $incrementor );
|
||||
wp_cache_add( $term->slug, $term->term_id, $taxonomy . ':slugs:' . $incrementor );
|
||||
wp_cache_add( $term->name, $term->term_id, $taxonomy . ':names:' . $incrementor );
|
||||
|
||||
if ( $output == OBJECT ) {
|
||||
return $term;
|
||||
@ -3670,7 +3670,7 @@ function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {
|
||||
do_action( 'clean_term_cache', $ids, $taxonomy );
|
||||
}
|
||||
|
||||
wp_get_last_changed( 'terms', true );
|
||||
wp_cache_set( 'last_changed', microtime(), 'terms' );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3776,10 +3776,11 @@ function update_term_cache($terms, $taxonomy = '') {
|
||||
if ( empty($term_taxonomy) )
|
||||
$term_taxonomy = $term->taxonomy;
|
||||
|
||||
wp_cache_add( $term->term_id, $term, $term_taxonomy );
|
||||
$group = $term_taxonomy . ':' . wp_get_last_changed( 'terms', true );
|
||||
wp_cache_add( "slug:{$term->slug}", $term->term_id, $group );
|
||||
wp_cache_add( "name:" . md5( $term->name ), $term->term_id, $group );
|
||||
$incrementor = wp_cache_set( 'last_changed', microtime(), 'terms' );
|
||||
|
||||
wp_cache_add( $term->term_id, $term, $term_taxonomy . ':terms:' . $incrementor );
|
||||
wp_cache_add( $term->slug, $term->term_id, $taxonomy . ':slugs:' . $incrementor );
|
||||
wp_cache_add( $term->name, $term->term_id, $taxonomy . ':names:' . $incrementor );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.1-alpha-30072';
|
||||
$wp_version = '4.1-alpha-30073';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user