Changeset 56585
- Timestamp:
- 09/14/2023 12:38:04 PM (12 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-term-query.php
r56555 r56585 92 92 * @since 5.1.0 Introduced the 'meta_compare_key' parameter. 93 93 * @since 5.3.0 Introduced the 'meta_type_key' parameter. 94 94 95 * 95 96 * @param string|array $query { … … 179 180 * @type string $cache_domain Unique cache key to be produced when this query is stored in 180 181 * an object cache. Default 'core'. 182 181 183 * @type bool $update_term_meta_cache Whether to prime meta caches for matched terms. Default true. 182 184 * @type string|string[] $meta_key Meta key or keys to filter by. … … 221 223 'childless' => false, 222 224 'cache_domain' => 'core', 225 223 226 'update_term_meta_cache' => true, 224 227 'meta_query' => '', … … 777 780 } 778 781 779 $cache_key = $this->generate_cache_key( $args, $this->request ); 780 $cache = wp_cache_get( $cache_key, 'term-queries' ); 781 782 if ( false !== $cache ) { 783 if ( 'ids' === $_fields ) { 784 $cache = array_map( 'intval', $cache ); 785 } elseif ( 'count' !== $_fields ) { 786 if ( ( 'all_with_object_id' === $_fields && ! empty( $args['object_ids'] ) ) 782 if ( $args['cache_results'] ) { 783 $cache_key = $this->generate_cache_key( $args, $this->request ); 784 $cache = wp_cache_get( $cache_key, 'term-queries' ); 785 786 if ( false !== $cache ) { 787 if ( 'ids' === $_fields ) { 788 $cache = array_map( 'intval', $cache ); 789 } elseif ( 'count' !== $_fields ) { 790 if ( ( 'all_with_object_id' === $_fields && ! empty( $args['object_ids'] ) ) 787 791 || ( 'all' === $_fields && $args['pad_counts'] || $fields_is_filtered ) 788 ) { 789 $term_ids = wp_list_pluck( $cache, 'term_id' ); 790 } else { 791 $term_ids = array_map( 'intval', $cache ); 792 ) { 793 $term_ids = wp_list_pluck( $cache, 'term_id' ); 794 } else { 795 $term_ids = array_map( 'intval', $cache ); 796 } 797 798 _prime_term_caches( $term_ids, $args['update_term_meta_cache'] ); 799 800 $term_objects = $this->populate_terms( $cache ); 801 $cache = $this->format_terms( $term_objects, $_fields ); 792 802 } 793 803 794 _prime_term_caches( $term_ids, $args['update_term_meta_cache'] ); 795 796 $term_objects = $this->populate_terms( $cache ); 797 $cache = $this->format_terms( $term_objects, $_fields ); 798 } 799 800 $this->terms = $cache; 801 return $this->terms; 804 $this->terms = $cache; 805 return $this->terms; 806 } 802 807 } 803 808 804 809 if ( 'count' === $_fields ) { 805 810 $count = $wpdb->get_var( $this->request ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared 806 wp_cache_set( $cache_key, $count, 'term-queries' ); 811 if ( $args['cache_results'] ) { 812 wp_cache_set( $cache_key, $count, 'term-queries' ); 813 } 807 814 return $count; 808 815 } … … 811 818 812 819 if ( empty( $terms ) ) { 813 wp_cache_add( $cache_key, array(), 'term-queries' ); 820 if ( $args['cache_results'] ) { 821 wp_cache_add( $cache_key, array(), 'term-queries' ); 822 } 814 823 return array(); 815 824 } … … 893 902 } 894 903 895 wp_cache_add( $cache_key, $term_cache, 'term-queries' ); 904 if ( $args['cache_results'] ) { 905 wp_cache_add( $cache_key, $term_cache, 'term-queries' ); 906 } 907 896 908 $this->terms = $this->format_terms( $term_objects, $_fields ); 897 909 … … 1154 1166 $cache_args = wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ); 1155 1167 1156 unset( $cache_args[' update_term_meta_cache'] );1168 unset( $cache_args['update_term_meta_cache'] ); 1157 1169 1158 1170 if ( 'count' !== $args['fields'] && 'all_with_object_id' !== $args['fields'] ) { -
trunk/src/wp-includes/taxonomy.php
r56549 r56585 1542 1542 // Ensure that while importing, queries are not cached. 1543 1543 if ( ! empty( $_wp_suspend_cache_invalidation ) ) { 1544 // @todo Disable caching once #52710 is merged. 1545 $defaults['cache_domain'] = microtime(); 1544 $defaults['cache_results'] = false; 1546 1545 } 1547 1546 -
trunk/tests/phpunit/tests/term/getTerms.php
r56548 r56585 3027 3027 3028 3028 /** 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3029 3062 * @ticket 35935 3030 3063 */
Note: See TracChangeset
for help on using the changeset viewer.