Make WordPress Core

Changeset 6243


Ignore:
Timestamp:
10/13/2007 06:23:59 PM (17 years ago)
Author:
ryan
Message:

Eliminate object_term_cache array. see #5182

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r6241 r6243  
    11601160        foreach ($terms as $term) {
    11611161            $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) );
    1162             $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxnomy_id' => $term ) );
     1162            $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
    11631163        }
    11641164
     
    11751175
    11761176function clean_object_term_cache($object_ids, $object_type) {
    1177     global $object_term_cache, $blog_id;
    1178 
    11791177    if ( !is_array($object_ids) )
    11801178        $object_ids = array($object_ids);
    11811179
    1182     $taxonomies = get_object_taxonomies($object_type);
    1183 
    1184     foreach ( $object_ids as $id ) {
    1185         foreach ( $taxonomies as $taxonomy ) {
    1186             if ( isset($object_term_cache[$blog_id][$id][$taxonomy]) )
    1187                 unset($object_term_cache[$blog_id][$id][$taxonomy]);
    1188         }
    1189     }
     1180    foreach ( $object_ids as $id )
     1181        wp_cache_delete($id, 'object_terms');
    11901182}
    11911183
     
    12231215
    12241216function &get_object_term_cache($id, $taxonomy) {
    1225     global $object_term_cache, $blog_id;
    1226 
    1227     if ( isset($object_term_cache[$blog_id][$id][$taxonomy]) )
    1228         return $object_term_cache[$blog_id][$id][$taxonomy];
    1229 
    1230     if ( isset($object_term_cache[$blog_id][$id]) )
    1231         return array();
     1217    $terms = wp_cache_get($id, 'object_terms');
     1218    if ( false !== $terms ) {
     1219        if ( isset($terms[$taxonomy]) )
     1220            return $terms[$taxonomy];
     1221        else
     1222            return array();
     1223    }
    12321224
    12331225    return false;
     
    12351227
    12361228function update_object_term_cache($object_ids, $object_type) {
    1237     global $wpdb, $object_term_cache, $blog_id;
     1229    global $wpdb;
    12381230
    12391231    if ( empty($object_ids) )
     
    12431235        $object_ids = explode(',', $object_ids);
    12441236
    1245     $count = count( $object_ids);
    1246     for ( $i = 0; $i < $count; $i++ ) {
    1247         $object_id = (int) $object_ids[ $i ];
    1248         if ( isset( $object_term_cache[$blog_id][$object_id] ) ) {
    1249             unset( $object_ids[ $i ] );
    1250             continue;
    1251         }
    1252     }
    1253 
    1254     if ( count( $object_ids ) == 0 )
    1255         return;
    1256 
    1257     $terms = wp_get_object_terms($object_ids, get_object_taxonomies($object_type), 'fields=all_with_object_id');
    1258 
    1259     if ( empty($terms) )
    1260         return;
    1261 
    1262     foreach ( $terms as $term )
    1263         $object_term_cache[$blog_id][$term->object_id][$term->taxonomy][$term->term_id] = $term;
    1264 
    1265     foreach ( $object_ids as $id ) {
    1266         if ( ! isset($object_term_cache[$blog_id][$id]) )
    1267                 $object_term_cache[$blog_id][$id] = array();
    1268     }
     1237    $object_ids = array_map('intval', $object_ids);
     1238
     1239    $ids = array();
     1240    foreach ( (array) $object_ids as $id ) {
     1241        if ( false === wp_cache_get($id, 'object_terms') )
     1242            $ids[] = $id;
     1243    }
     1244
     1245    if ( empty( $ids ) )
     1246        return false;
     1247
     1248    $terms = wp_get_object_terms($ids, get_object_taxonomies($object_type), 'fields=all_with_object_id');
     1249
     1250    $object_terms = array();
     1251    foreach ( (array) $terms as $term )
     1252        $object_terms[$term->object_id][$term->taxonomy][$term->term_id] = $term;
     1253
     1254    foreach ( $ids as $id ) {
     1255        if ( ! isset($object_terms[$id]) )
     1256                $object_terms[$id] = array();
     1257    }
     1258
     1259    foreach ( $object_terms as $id => $value )
     1260        wp_cache_set($id, $value, 'object_terms');
    12691261}
    12701262
     
    13941386    foreach ( $terms as $term ) {
    13951387        $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 ) );
    1396         $wpdb->update( $wpdb->term_taxnomoy, compact( 'count' ), array( 'term_taxnomy_id' => $term ) );
     1388        $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
    13971389    }
    13981390}
Note: See TracChangeset for help on using the changeset viewer.