mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 17:48:01 +01:00
Eliminate object_term_cache array. see #5182
git-svn-id: http://svn.automattic.com/wordpress/trunk@6243 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4a43a0b353
commit
a8d380c32c
@ -1159,7 +1159,7 @@ function wp_update_term_count( $terms, $taxonomy ) {
|
|||||||
// Default count updater
|
// Default count updater
|
||||||
foreach ($terms as $term) {
|
foreach ($terms as $term) {
|
||||||
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) );
|
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) );
|
||||||
$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxnomy_id' => $term ) );
|
$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1174,19 +1174,11 @@ function wp_update_term_count( $terms, $taxonomy ) {
|
|||||||
//
|
//
|
||||||
|
|
||||||
function clean_object_term_cache($object_ids, $object_type) {
|
function clean_object_term_cache($object_ids, $object_type) {
|
||||||
global $object_term_cache, $blog_id;
|
|
||||||
|
|
||||||
if ( !is_array($object_ids) )
|
if ( !is_array($object_ids) )
|
||||||
$object_ids = array($object_ids);
|
$object_ids = array($object_ids);
|
||||||
|
|
||||||
$taxonomies = get_object_taxonomies($object_type);
|
foreach ( $object_ids as $id )
|
||||||
|
wp_cache_delete($id, 'object_terms');
|
||||||
foreach ( $object_ids as $id ) {
|
|
||||||
foreach ( $taxonomies as $taxonomy ) {
|
|
||||||
if ( isset($object_term_cache[$blog_id][$id][$taxonomy]) )
|
|
||||||
unset($object_term_cache[$blog_id][$id][$taxonomy]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clean_term_cache($ids, $taxonomy = '') {
|
function clean_term_cache($ids, $taxonomy = '') {
|
||||||
@ -1222,19 +1214,19 @@ function clean_term_cache($ids, $taxonomy = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function &get_object_term_cache($id, $taxonomy) {
|
function &get_object_term_cache($id, $taxonomy) {
|
||||||
global $object_term_cache, $blog_id;
|
$terms = wp_cache_get($id, 'object_terms');
|
||||||
|
if ( false !== $terms ) {
|
||||||
if ( isset($object_term_cache[$blog_id][$id][$taxonomy]) )
|
if ( isset($terms[$taxonomy]) )
|
||||||
return $object_term_cache[$blog_id][$id][$taxonomy];
|
return $terms[$taxonomy];
|
||||||
|
else
|
||||||
if ( isset($object_term_cache[$blog_id][$id]) )
|
|
||||||
return array();
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_object_term_cache($object_ids, $object_type) {
|
function update_object_term_cache($object_ids, $object_type) {
|
||||||
global $wpdb, $object_term_cache, $blog_id;
|
global $wpdb;
|
||||||
|
|
||||||
if ( empty($object_ids) )
|
if ( empty($object_ids) )
|
||||||
return;
|
return;
|
||||||
@ -1242,30 +1234,30 @@ function update_object_term_cache($object_ids, $object_type) {
|
|||||||
if ( !is_array($object_ids) )
|
if ( !is_array($object_ids) )
|
||||||
$object_ids = explode(',', $object_ids);
|
$object_ids = explode(',', $object_ids);
|
||||||
|
|
||||||
$count = count( $object_ids);
|
$object_ids = array_map('intval', $object_ids);
|
||||||
for ( $i = 0; $i < $count; $i++ ) {
|
|
||||||
$object_id = (int) $object_ids[ $i ];
|
$ids = array();
|
||||||
if ( isset( $object_term_cache[$blog_id][$object_id] ) ) {
|
foreach ( (array) $object_ids as $id ) {
|
||||||
unset( $object_ids[ $i ] );
|
if ( false === wp_cache_get($id, 'object_terms') )
|
||||||
continue;
|
$ids[] = $id;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( count( $object_ids ) == 0 )
|
if ( empty( $ids ) )
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
$terms = wp_get_object_terms($object_ids, get_object_taxonomies($object_type), 'fields=all_with_object_id');
|
$terms = wp_get_object_terms($ids, get_object_taxonomies($object_type), 'fields=all_with_object_id');
|
||||||
|
|
||||||
if ( empty($terms) )
|
$object_terms = array();
|
||||||
return;
|
foreach ( (array) $terms as $term )
|
||||||
|
$object_terms[$term->object_id][$term->taxonomy][$term->term_id] = $term;
|
||||||
|
|
||||||
foreach ( $terms as $term )
|
foreach ( $ids as $id ) {
|
||||||
$object_term_cache[$blog_id][$term->object_id][$term->taxonomy][$term->term_id] = $term;
|
if ( ! isset($object_terms[$id]) )
|
||||||
|
$object_terms[$id] = array();
|
||||||
foreach ( $object_ids as $id ) {
|
|
||||||
if ( ! isset($object_term_cache[$blog_id][$id]) )
|
|
||||||
$object_term_cache[$blog_id][$id] = array();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ( $object_terms as $id => $value )
|
||||||
|
wp_cache_set($id, $value, 'object_terms');
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_term_cache($terms, $taxonomy = '') {
|
function update_term_cache($terms, $taxonomy = '') {
|
||||||
@ -1393,7 +1385,7 @@ function _update_post_term_count( $terms ) {
|
|||||||
|
|
||||||
foreach ( $terms as $term ) {
|
foreach ( $terms as $term ) {
|
||||||
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term ) );
|
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term ) );
|
||||||
$wpdb->update( $wpdb->term_taxnomoy, compact( 'count' ), array( 'term_taxnomy_id' => $term ) );
|
$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user