Cache results in `get_objects_in_term()`.

This helps to reduce database queries when generating nav menus.

Props spacedmonkey.
Fixes #37094.
Built from https://develop.svn.wordpress.org/trunk@40921


git-svn-id: http://core.svn.wordpress.org/trunk@40771 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2017-06-22 03:19:44 +00:00
parent 8ca91024e8
commit 2ebc1fb143
2 changed files with 12 additions and 2 deletions

View File

@ -650,7 +650,17 @@ function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) {
$taxonomies = "'" . implode( "', '", array_map( 'esc_sql', $taxonomies ) ) . "'";
$term_ids = "'" . implode( "', '", $term_ids ) . "'";
$object_ids = $wpdb->get_col("SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tt.term_id IN ($term_ids) ORDER BY tr.object_id $order");
$sql = "SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tt.term_id IN ($term_ids) ORDER BY tr.object_id $order";
$last_changed = wp_cache_get_last_changed( 'terms' );
$cache_key = 'get_objects_in_term:' . md5( $sql ) . ":$last_changed";
$cache = wp_cache_get( $cache_key, 'terms' );
if ( false === $cache ) {
$object_ids = $wpdb->get_col( $sql );
wp_cache_set( $cache_key, $object_ids, 'terms' );
} else {
$object_ids = (array) $cache;
}
if ( ! $object_ids ){
return array();

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-40920';
$wp_version = '4.9-alpha-40921';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.