Ticket #37189: 37189.patch
File 37189.patch, 5.6 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-term-query.php
585 585 586 586 $selects = array(); 587 587 switch ( $args['fields'] ) { 588 case 'all':589 case 'all_with_object_id' :590 case 'tt_ids' :591 case 'slugs' :592 $selects = array( 't.*', 'tt.*' );593 if ( 'all_with_object_id' === $args['fields'] && ! empty( $args['object_ids'] ) ) {594 $selects[] = 'tr.object_id';595 }596 break;597 case 'ids':598 case 'id=>parent':599 $selects = array( 't.term_id', 'tt.parent', 'tt.count', 'tt.taxonomy' );600 break;601 case 'names':602 $selects = array( 't.term_id', 'tt.parent', 'tt.count', 't.name', 'tt.taxonomy' );603 break;604 588 case 'count': 605 589 $orderby = ''; 606 590 $order = ''; 607 591 $selects = array( 'COUNT(*)' ); 608 592 break; 609 case 'id=>name':610 $selects = array( 't. term_id', 't.name', 'tt.count', 'tt.taxonomy' );611 break;612 case 'id=>slug':613 $selects = array( 't.term_id', 't.slug', 'tt.count', 'tt.taxonomy' );593 default: 594 $selects = array( 't.*', 'tt.*' ); 595 if ( 'all_with_object_id' === $args['fields'] && ! empty( $args['object_ids'] ) ) { 596 $selects[] = 'tr.object_id'; 597 } 614 598 break; 599 615 600 } 616 601 617 602 $_fields = $args['fields']; … … 672 657 673 658 $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; 674 659 675 // $args can be anything. Only use the args defined in defaults to compute the key. 676 $key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ) ) . serialize( $taxonomies ) . $this->request ); 660 // $args can be anything. Only use the args defined in defaults to compute the key; 661 $_args = wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ); 662 unset( $_args['fields'] ); 663 $key = md5( serialize( $_args ) . serialize( $taxonomies ) . $this->request ); 677 664 $last_changed = wp_cache_get_last_changed( 'terms' ); 678 665 $cache_key = "get_terms:$key:$last_changed"; 679 666 $cache = wp_cache_get( $cache_key, 'terms' ); 680 667 if ( false !== $cache ) { 681 if ( 'all' === $_fields ) { 682 $cache = array_map( 'get_term', $cache ); 668 $_terms = array(); 669 if ( ! in_array( $_fields, array( 'ids', 'count' ) ) ) { 670 $terms = array_map( 'get_term', $cache ); 671 if ( 'id=>parent' == $_fields ) { 672 foreach ( $terms as $term ) { 673 $_terms[ $term->term_id ] = $term->parent; 674 } 675 } elseif ( 'tt_ids' == $_fields ) { 676 foreach ( $terms as $term ) { 677 $_terms[] = (int) $term->term_taxonomy_id; 678 } 679 } elseif ( 'names' == $_fields ) { 680 foreach ( $terms as $term ) { 681 $_terms[] = $term->name; 682 } 683 } elseif ( 'slugs' == $_fields ) { 684 foreach ( $terms as $term ) { 685 $_terms[] = $term->slug; 686 } 687 } elseif ( 'id=>name' == $_fields ) { 688 foreach ( $terms as $term ) { 689 $_terms[ $term->term_id ] = $term->name; 690 } 691 } elseif ( 'id=>slug' == $_fields ) { 692 foreach ( $terms as $term ) { 693 $_terms[ $term->term_id ] = $term->slug; 694 } 695 } else { 696 $_terms = $terms; 697 } 698 } else { 699 $_terms = $cache; 683 700 } 684 701 685 $this->terms = $ cache;702 $this->terms = $_terms; 686 703 return $this->terms; 687 704 } 688 705 689 706 if ( 'count' == $_fields ) { 690 707 $count = $wpdb->get_var( $this->request ); 691 708 wp_cache_set( $cache_key, $count, 'terms' ); 709 692 710 return $count; 693 711 } 694 712 695 $terms = $wpdb->get_results( $this->request ); 696 if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) { 697 update_term_cache( $terms ); 698 } 713 $terms = $wpdb->get_results( $this->request ); 714 $term_ids = wp_list_pluck( $terms, 'term_id' ); 715 $term_ids = array_map( 'intval', $term_ids ); 716 717 update_term_cache( $terms ); 718 $terms = array_map( 'get_term', $terms ); 699 719 700 720 // Prime termmeta cache. 701 721 if ( $args['update_term_meta_cache'] ) { 702 $term_ids = wp_list_pluck( $terms, 'term_id' );703 722 update_termmeta_cache( $term_ids ); 704 723 } 705 724 706 725 if ( empty( $terms ) ) { 707 726 wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS ); 727 708 728 return array(); 709 729 } 710 730 731 711 732 if ( $child_of ) { 712 733 foreach ( $taxonomies as $_tax ) { 713 734 $children = _get_term_hierarchy( $_tax ); … … 758 779 } 759 780 760 781 $_tt_ids[ $term->term_id ] = 1; 761 $_terms[] = $term;782 $_terms[] = $term; 762 783 } 763 784 764 785 $terms = $_terms; … … 808 829 } 809 830 } 810 831 811 wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS );812 832 813 if ( 'all' === $_fields || 'all_with_object_id' === $_fields ) { 814 $terms = array_map( 'get_term', $terms ); 815 } 833 wp_cache_add( $cache_key, $term_ids, 'terms', DAY_IN_SECONDS ); 834 816 835 817 836 $this->terms = $terms; 837 818 838 return $this->terms; 819 839 } 820 840 -
src/wp-includes/class-wp-term.php
134 134 135 135 // If there isn't a cached version, hit the database. 136 136 if ( ! $_term || ( $taxonomy && $taxonomy !== $_term->taxonomy ) ) { 137 137 138 // Grab all matching terms, in case any are shared between taxonomies. 138 139 $terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id = %d", $term_id ) ); 139 140 if ( ! $terms ) { 140 141 return false; 141 142 } 143 $_term = false; 142 144 143 145 // If a taxonomy was specified, find a match. 144 146 if ( $taxonomy ) { 147 145 148 foreach ( $terms as $match ) { 146 149 if ( $taxonomy === $match->taxonomy ) { 147 150 $_term = $match;