Make WordPress Core


Ignore:
Timestamp:
05/23/2014 07:28:45 PM (11 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/template.php

    r28514 r28561  
    365365
    366366        if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
    367                 echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">'
    368                     . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array( 'fields' => 'ids' ) ) ) . '</div>';
     367
     368            $terms = get_object_term_cache( $post->ID, $taxonomy_name );
     369            if ( false === $terms ) {
     370                $terms = wp_get_object_terms( $post->ID, $taxonomy_name );
     371                wp_cache_add( $post->ID, $terms, $taxonomy_name . '_relationships' );
     372            }
     373            $term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' );
     374
     375            echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>';
     376
    369377        } elseif ( $taxonomy->show_ui ) {
     378
    370379            echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">'
    371380                . esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '</div>';
     381
    372382        }
    373383    }
Note: See TracChangeset for help on using the changeset viewer.