From 40e61f93e52873f615a88ae881a7317ecc18bcf2 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 27 Jan 2010 19:42:23 +0000 Subject: [PATCH] Change back to an option so that it is always there and regenerate it after cleaning the cache instead of waiting for the next page load. Don't clean taxonomy wide caches when just updating object counts to avoid cleaning when updating a post. git-svn-id: http://svn.automattic.com/wordpress/trunk@12881 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 3 +-- wp-includes/taxonomy.php | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 73d5fbeda..2df6712dd 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2043,9 +2043,8 @@ function wp_insert_post($postarr = array(), $wp_error = false) { wp_set_post_tags( $post_ID, $tags_input ); // new-style support for all tag-like taxonomies if ( !empty($tax_input) ) { - foreach ( $tax_input as $taxonomy => $tags ) { + foreach ( $tax_input as $taxonomy => $tags ) wp_set_post_terms( $post_ID, $tags, $taxonomy ); - } } $current_guid = get_post_field( 'guid', $post_ID ); diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 1a5609a1c..b5e511b5a 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1867,7 +1867,7 @@ function wp_update_term_count_now( $terms, $taxonomy ) { } - clean_term_cache($terms); + clean_term_cache($terms, '', false); return true; } @@ -1917,8 +1917,9 @@ function clean_object_term_cache($object_ids, $object_type) { * * @param int|array $ids Single or list of Term IDs * @param string $taxonomy Can be empty and will assume tt_ids, else will use for context. + * @param bool $clean_taxonomy Whether to clean taxonomy wide caches (true), or just individual term object caches (false). Default is true. */ -function clean_term_cache($ids, $taxonomy = '') { +function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { global $wpdb; static $cleaned = array(); @@ -1951,9 +1952,15 @@ function clean_term_cache($ids, $taxonomy = '') { if ( isset($cleaned[$taxonomy]) ) continue; $cleaned[$taxonomy] = true; - wp_cache_delete('all_ids', $taxonomy); - wp_cache_delete('get', $taxonomy); - delete_transient("{$taxonomy}_children"); + + if ( $clean_taxonomy ) { + wp_cache_delete('all_ids', $taxonomy); + wp_cache_delete('get', $taxonomy); + delete_option("{$taxonomy}_children"); + // Regenerate {$taxonomy}_children + _get_term_hierarchy($taxonomy); + } + do_action('clean_term_cache', $ids, $taxonomy); } @@ -2092,17 +2099,17 @@ function update_term_cache($terms, $taxonomy = '') { function _get_term_hierarchy($taxonomy) { if ( !is_taxonomy_hierarchical($taxonomy) ) return array(); - $children = get_transient("{$taxonomy}_children"); + $children = get_option("{$taxonomy}_children"); + if ( is_array($children) ) return $children; - $children = array(); $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent')); foreach ( $terms as $term_id => $parent ) { if ( $parent > 0 ) $children[$parent][] = $term_id; } - set_transient("{$taxonomy}_children", $children); + update_option("{$taxonomy}_children", $children); return $children; }