Ticket #14485: garyc40-14485-rev5.patch
File garyc40-14485-rev5.patch, 3.5 KB (added by , 14 years ago) |
---|
-
wp-includes/taxonomy.php
1150 1150 // $args can be whatever, only use the args defined in defaults to compute the key 1151 1151 $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : ''; 1152 1152 $key = md5( serialize( compact(array_keys($defaults)) ) . serialize( $taxonomies ) . $filter_key ); 1153 $last_changed = wp_cache_get('last_changed', 'terms'); 1154 if ( !$last_changed ) { 1155 $last_changed = time(); 1156 wp_cache_set('last_changed', $last_changed, 'terms'); 1153 $cache_key = "get_terms:$key"; 1154 1155 // save $key so that it could be invalidated later 1156 $cache_keys = wp_cache_get( 'get_terms:cache_keys', 'terms' ); 1157 if ( ! $cache_keys ) { 1158 $cache_keys = array(); 1157 1159 } 1158 $cache_key = "get_terms:$key:$last_changed"; 1160 if ( ! in_array( $key, $cache_keys ) ) { 1161 $cache_keys[] = $key; 1162 } 1163 wp_cache_set( 'get_terms:cache_keys', $cache_keys, 'terms' ); 1164 1159 1165 $cache = wp_cache_get( $cache_key, 'terms' ); 1160 1166 if ( false !== $cache ) { 1161 1167 $cache = apply_filters('get_terms', $cache, $taxonomies, $args); … … 1297 1303 1298 1304 if ( 'count' == $fields ) { 1299 1305 $term_count = $wpdb->get_var($query); 1306 wp_cache_add( $cache_key, $term_count, 'terms' ); 1300 1307 return $term_count; 1301 1308 } 1302 1309 … … 1707 1714 if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) ) 1708 1715 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->terms WHERE term_id = %d", $term) ); 1709 1716 1710 clean_term_cache($term, $taxonomy );1717 clean_term_cache($term, $taxonomy, true, true); 1711 1718 1712 1719 do_action('delete_term', $term, $tt_id, $taxonomy); 1713 1720 do_action("delete_$taxonomy", $term, $tt_id); … … 2001 2008 2002 2009 $term_id = apply_filters('term_id_filter', $term_id, $tt_id); 2003 2010 2004 clean_term_cache($term_id, $taxonomy);2011 $force_clean_taxonomy = ( $parent ) ? true : false; 2005 2012 2013 clean_term_cache($term_id, $taxonomy, true, $force_clean_taxonomy); 2014 2006 2015 do_action("created_term", $term_id, $tt_id, $taxonomy); 2007 2016 do_action("created_$taxonomy", $term_id, $tt_id); 2008 2017 … … 2440 2449 * @param int|array $ids Single or list of Term IDs 2441 2450 * @param string $taxonomy Can be empty and will assume tt_ids, else will use for context. 2442 2451 * @param bool $clean_taxonomy Whether to clean taxonomy wide caches (true), or just individual term object caches (false). Default is true. 2452 * @param bool $force_clean_taxonomy Whether to force clean taxonomy wide caches (true), or skip if it's already done (false). Default is false 2453 * 2443 2454 */ 2444 function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true ) {2455 function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true, $force_clean_taxonomy = false) { 2445 2456 global $wpdb; 2446 2457 static $cleaned = array(); 2447 2458 … … 2471 2482 } 2472 2483 2473 2484 foreach ( $taxonomies as $taxonomy ) { 2474 if ( isset($cleaned[$taxonomy]) )2485 if ( isset($cleaned[$taxonomy]) && ! $force_clean_taxonomy ) 2475 2486 continue; 2476 2487 $cleaned[$taxonomy] = true; 2477 2488 … … 2486 2497 do_action('clean_term_cache', $ids, $taxonomy); 2487 2498 } 2488 2499 2489 wp_cache_set('last_changed', time(), 'terms'); 2500 // invalidate all get_terms cache values 2501 $cache_keys = wp_cache_get( 'get_terms:cache_keys', 'terms' ); 2502 if ( ! empty( $cache_keys ) ) { 2503 foreach ( $cache_keys as $key ) { 2504 wp_cache_delete( "get_terms:{$key}", 'terms' ); 2505 } 2506 wp_cache_delete( 'get_terms:cache_keys', 'terms' ); 2507 } 2490 2508 }