Make WordPress Core


Ignore:
Timestamp:
05/30/2007 03:36:59 AM (19 years ago)
Author:
ryan
Message:

Some term caching. see #4189

File:
1 edited

Legend:

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

    r5597 r5598  
    429429
    430430        if ( 'all' == $fields )
    431                 $select_this = 't.*';
     431                $select_this = 't.*, tt.*';
    432432        else if ( 'ids' == $fields )
    433433                $select_this = 't.term_id';
     434        else if ( 'all_with_object_id' == $fields )
     435                $select_this = 't.*, tt.*, tr.object_id';
    434436
    435437        $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) ORDER BY $orderby $order";
    436438
    437         if ( 'all' == $fields )
    438                 $taxonomy_data = $wpdb->get_results($query);
    439         else if ( 'ids' == $fields )
    440                 $taxonomy_data = $wpdb->get_col($query);
    441         else if ( 'tt_ids' == $fields )
    442                 $taxonomy_data = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) ORDER BY tr.term_taxonomy_id $order");
    443 
    444         if ( ! $taxonomy_data )
     439        if ( 'all' == $fields || 'all_with_object_id' == $fields ) {
     440                $terms = $wpdb->get_results($query);
     441                update_term_cache($terms);
     442        } else if ( 'ids' == $fields ) {
     443                $terms = $wpdb->get_col($query);
     444        } else if ( 'tt_ids' == $fields ) {
     445                $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) ORDER BY tr.term_taxonomy_id $order");
     446        }
     447
     448        if ( ! $terms )
    445449                return array();
    446450
    447         return $taxonomy_data;
     451        return $terms;
    448452}
    449453
     
    554558        $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $number";
    555559
    556         if ( 'all' == $fields )
     560        if ( 'all' == $fields ) {
    557561                $terms = $wpdb->get_results($query);
    558         else if ( 'ids' == $fields )
     562                update_term_cache($terms);
     563        } else if ( 'ids' == $fields ) {
    559564                $terms = $wpdb->get_col($query);
     565        }
    560566
    561567        if ( empty($terms) )
     
    591597
    592598        $cache[ $key ] = $terms;
    593         wp_cache_add( 'get_terms', $cache, 'term' );
     599        wp_cache_set( 'get_terms', $cache, 'term' );
    594600
    595601        $terms = apply_filters('get_terms', $terms, $taxonomies, $args);
     
    680686}
    681687
     688function update_term_cache($terms, $taxonomy = '') {
     689        foreach ( $terms as $term ) {
     690                $term_taxonomy = $taxonomy;
     691                if ( empty($term_taxonomy) )
     692                        $term_taxonomy = $term->taxonomy;
     693
     694                wp_cache_add($term->term_id, $term, $term_taxonomy);
     695        }
     696}
     697
    682698function clean_term_cache($ids, $taxonomy) {
    683699        if ( !is_array($ids) )
Note: See TracChangeset for help on using the changeset viewer.