From 9db4d2042e75b6ca59a4e1919dbf61e05e32e181 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 23 Oct 2007 20:33:50 +0000 Subject: [PATCH] Separate taxonomy relationships into separate cache buckets. git-svn-id: http://svn.automattic.com/wordpress/trunk@6286 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 1f86b1f73c..9c558b395a 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1429,15 +1429,7 @@ function clean_term_cache($ids, $taxonomy = '') { * @return bool|array Empty array if $terms found, but not $taxonomy. False if nothing is in cache for $taxonomy and $id. */ function &get_object_term_cache($id, $taxonomy) { - $terms = wp_cache_get($id, 'object_terms'); - if ( false !== $terms ) { - if ( isset($terms[$taxonomy]) ) - return $terms[$taxonomy]; - else - return array(); - } - - return false; + return wp_cache_get($id, "{$taxonomy}_relationships"); } /** @@ -1465,28 +1457,42 @@ function update_object_term_cache($object_ids, $object_type) { $object_ids = array_map('intval', $object_ids); + $taxonomies = get_object_taxonomies($object_type); + $ids = array(); foreach ( (array) $object_ids as $id ) { - if ( false === wp_cache_get($id, 'object_terms') ) - $ids[] = $id; + foreach ( $taxonomies as $taxonomy ) { + if ( false === wp_cache_get($id, "{$taxonomy}_relationships") ) { + $ids[] = $id; + break; + } + } } if ( empty( $ids ) ) return false; - $terms = wp_get_object_terms($ids, get_object_taxonomies($object_type), 'fields=all_with_object_id'); + $terms = wp_get_object_terms($ids, $taxonomies, 'fields=all_with_object_id'); $object_terms = array(); foreach ( (array) $terms as $term ) $object_terms[$term->object_id][$term->taxonomy][$term->term_id] = $term; foreach ( $ids as $id ) { - if ( ! isset($object_terms[$id]) ) - $object_terms[$id] = array(); + foreach ( $taxonomies as $taxonomy ) { + if ( ! isset($object_terms[$id][$taxonomy]) ) { + if ( !isset($object_terms[$id]) ) + $object_terms[$id] = array(); + $object_terms[$id][$taxonomy] = array(); + } + } } - foreach ( $object_terms as $id => $value ) - wp_cache_set($id, $value, 'object_terms'); + foreach ( $object_terms as $id => $value ) { + foreach ( $value as $taxonomy => $terms ) { + wp_cache_set($id, $terms, "{$taxonomy}_relationships"); + } + } } /**