Separate taxonomy relationships into separate cache buckets.

git-svn-id: http://svn.automattic.com/wordpress/trunk@6286 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-10-23 20:33:50 +00:00
parent 6e7729018e
commit 9db4d2042e
1 changed files with 22 additions and 16 deletions

View File

@ -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. * @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) { function &get_object_term_cache($id, $taxonomy) {
$terms = wp_cache_get($id, 'object_terms'); return wp_cache_get($id, "{$taxonomy}_relationships");
if ( false !== $terms ) {
if ( isset($terms[$taxonomy]) )
return $terms[$taxonomy];
else
return array();
}
return false;
} }
/** /**
@ -1465,28 +1457,42 @@ function update_object_term_cache($object_ids, $object_type) {
$object_ids = array_map('intval', $object_ids); $object_ids = array_map('intval', $object_ids);
$taxonomies = get_object_taxonomies($object_type);
$ids = array(); $ids = array();
foreach ( (array) $object_ids as $id ) { foreach ( (array) $object_ids as $id ) {
if ( false === wp_cache_get($id, 'object_terms') ) foreach ( $taxonomies as $taxonomy ) {
$ids[] = $id; if ( false === wp_cache_get($id, "{$taxonomy}_relationships") ) {
$ids[] = $id;
break;
}
}
} }
if ( empty( $ids ) ) if ( empty( $ids ) )
return false; 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(); $object_terms = array();
foreach ( (array) $terms as $term ) foreach ( (array) $terms as $term )
$object_terms[$term->object_id][$term->taxonomy][$term->term_id] = $term; $object_terms[$term->object_id][$term->taxonomy][$term->term_id] = $term;
foreach ( $ids as $id ) { foreach ( $ids as $id ) {
if ( ! isset($object_terms[$id]) ) foreach ( $taxonomies as $taxonomy ) {
$object_terms[$id] = array(); 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 ) foreach ( $object_terms as $id => $value ) {
wp_cache_set($id, $value, 'object_terms'); foreach ( $value as $taxonomy => $terms ) {
wp_cache_set($id, $terms, "{$taxonomy}_relationships");
}
}
} }
/** /**