Make WordPress Core

Changeset 5983


Ignore:
Timestamp:
08/30/2007 12:34:55 AM (18 years ago)
Author:
ryan
Message:

Make sure term cache is cleared when updating term counts.

File:
1 edited

Legend:

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

    r5979 r5983  
    641641        wp_update_term_count($terms, $taxonomy);
    642642    }
    643 
    644     // TODO clear the cache
    645643}
    646644
     
    871869    }
    872870
    873     // TODO clean old_terms. Need term_id instead of tt_id
    874     clean_term_cache($term_ids, $taxonomy);
    875 
    876871    return $tt_ids;
    877872}
     
    950945
    951946    $taxonomy = get_taxonomy($taxonomy);
    952     if ( !empty($taxonomy->update_count_callback) )
    953         return call_user_func($taxonomy->update_count_callback, $terms);
    954 
    955     // Default count updater
    956     foreach ($terms as $term) {
    957         $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term'");
    958         $wpdb->query("UPDATE $wpdb->term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term'");
    959     }
     947    if ( !empty($taxonomy->update_count_callback) ) {
     948        call_user_func($taxonomy->update_count_callback, $terms);
     949    } else {
     950        // Default count updater
     951        foreach ($terms as $term) {
     952            $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term'");
     953            $wpdb->query("UPDATE $wpdb->term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term'");
     954        }
     955
     956    }
     957
     958    clean_term_cache($terms);
    960959
    961960    return true;
     
    982981}
    983982
    984 function clean_term_cache($ids, $taxonomy) {
     983function clean_term_cache($ids, $taxonomy = '') {
     984    global $wpdb;
     985
    985986    if ( !is_array($ids) )
    986987        $ids = array($ids);
    987988
    988     foreach ( $ids as $id ) {
    989         wp_cache_delete($id, $taxonomy);
    990     }
    991 
    992     wp_cache_delete('all_ids', $taxonomy);
    993     wp_cache_delete('get', $taxonomy);
    994     delete_option("{$taxonomy}_children");
     989    $taxonomies = array();
     990    // If no taxonomy, assume tt_ids.
     991    if ( empty($taxonomy) ) {
     992        $tt_ids = implode(', ', $ids);
     993        $terms = $wpdb->get_results("SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)");
     994        foreach ( (array) $terms as $term ) {
     995            $taxonomies[] = $term->taxonomy;
     996            wp_cache_delete($term->term_id, $term->taxonomy);
     997        }
     998        $taxonomies = array_unique($taxonomies);
     999    } else {
     1000        foreach ( $ids as $id ) {
     1001            wp_cache_delete($id, $taxonomy);
     1002        }
     1003        $taxonomies = array($taxonomy);
     1004    }
     1005
     1006    foreach ( $taxonomies as $taxonomy ) {
     1007        wp_cache_delete('all_ids', $taxonomy);
     1008        wp_cache_delete('get', $taxonomy);
     1009        delete_option("{$taxonomy}_children");
     1010    }
     1011
    9951012    wp_cache_delete('get_terms', 'terms');
    9961013}
Note: See TracChangeset for help on using the changeset viewer.