Make WordPress Core


Ignore:
Timestamp:
05/23/2014 07:28:45 PM (12 years ago)
Author:
wonderboymusic
Message:

In get_terms_to_edit(), call get_object_term_cache() before priming cache with wp_get_object_terms().

In get_inline_data(), do the same.

On list table screens with taxonomies in the admin, this dramatically reduces the number of database queries (3x less). Even more so with a persistent object cache (5x less).

Props johnbillion, jeffstieler, wonderboymusic.
Fixes #18968.

File:
1 edited

Legend:

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

    r28500 r28561  
    235235                return false;
    236236
    237         $tags = wp_get_post_terms($post_id, $taxonomy, array());
    238 
    239         if ( !$tags ) {
     237        $terms = get_object_term_cache( $post_id, $taxonomy );
     238        if ( false === $terms ) {
     239                $terms = wp_get_object_terms( $post_id, $taxonomy );
     240                wp_cache_add( $post_id, $terms, $taxonomy . '_relationships' );
     241        }
     242
     243        if ( ! $terms ) {
    240244                return false;
    241245        }
    242         if ( is_wp_error($tags) ) {
    243                 return $tags;
    244         }
    245         $tag_names = array();
    246         foreach ( $tags as $tag ) {
    247                 $tag_names[] = $tag->name;
    248         }
    249 
    250         $tags_to_edit = esc_attr( join( ',', $tag_names ) );
     246        if ( is_wp_error( $terms ) ) {
     247                return $terms;
     248        }
     249        $term_names = array();
     250        foreach ( $terms as $term ) {
     251                $term_names[] = $term->name;
     252        }
     253
     254        $terms_to_edit = esc_attr( join( ',', $term_names ) );
    251255
    252256        /**
     
    257261         * @see get_terms_to_edit()
    258262         *
    259          * @param array  $tags_to_edit An array of terms.
     263         * @param array  $terms_to_edit An array of terms.
    260264         * @param string $taxonomy     The taxonomy for which to retrieve terms. Default 'post_tag'.
    261265         */
    262         $tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy );
    263 
    264         return $tags_to_edit;
     266        $terms_to_edit = apply_filters( 'terms_to_edit', $terms_to_edit, $taxonomy );
     267
     268        return $terms_to_edit;
    265269}
    266270
Note: See TracChangeset for help on using the changeset viewer.