Ticket #37189: 37189.2.patch
File 37189.2.patch, 5.7 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 ) ); var_dump($_args); 662 if ( 'count' != $_fields ) { 663 unset( $_args['fields'] ); 664 } 665 $key = md5( serialize( $_args ) . serialize( $taxonomies ) . $this->request ); 677 666 $last_changed = wp_cache_get_last_changed( 'terms' ); 678 667 $cache_key = "get_terms:$key:$last_changed"; 679 668 $cache = wp_cache_get( $cache_key, 'terms' ); 680 669 if ( false !== $cache ) { 681 if ( 'all' === $_fields ) { 682 $cache = array_map( 'get_term', $cache ); 670 $_terms = array(); 671 if ( ! in_array( $_fields, array( 'ids', 'count' ) ) ) { 672 $terms = array_map( 'get_term', $cache ); 673 if ( 'id=>parent' == $_fields ) { 674 foreach ( $terms as $term ) { 675 $_terms[ $term->term_id ] = $term->parent; 676 } 677 } elseif ( 'tt_ids' == $_fields ) { 678 foreach ( $terms as $term ) { 679 $_terms[] = (int) $term->term_taxonomy_id; 680 } 681 } elseif ( 'names' == $_fields ) { 682 foreach ( $terms as $term ) { 683 $_terms[] = $term->name; 684 } 685 } elseif ( 'slugs' == $_fields ) { 686 foreach ( $terms as $term ) { 687 $_terms[] = $term->slug; 688 } 689 } elseif ( 'id=>name' == $_fields ) { 690 foreach ( $terms as $term ) { 691 $_terms[ $term->term_id ] = $term->name; 692 } 693 } elseif ( 'id=>slug' == $_fields ) { 694 foreach ( $terms as $term ) { 695 $_terms[ $term->term_id ] = $term->slug; 696 } 697 } else { 698 $_terms = $terms; 699 } 700 } else { 701 $_terms = $cache; 683 702 } 684 703 685 $this->terms = $ cache;704 $this->terms = $_terms; 686 705 return $this->terms; 687 706 } 688 707 689 708 if ( 'count' == $_fields ) { 690 709 $count = $wpdb->get_var( $this->request ); 691 710 wp_cache_set( $cache_key, $count, 'terms' ); 711 692 712 return $count; 693 713 } 694 714 695 $terms = $wpdb->get_results( $this->request ); 696 if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) { 697 update_term_cache( $terms ); 698 } 715 $terms = $wpdb->get_results( $this->request ); 716 $term_ids = wp_list_pluck( $terms, 'term_id' ); 717 $term_ids = array_map( 'intval', $term_ids ); 718 719 update_term_cache( $terms ); 720 $terms = array_map( 'get_term', $terms ); 699 721 700 722 // Prime termmeta cache. 701 723 if ( $args['update_term_meta_cache'] ) { 702 $term_ids = wp_list_pluck( $terms, 'term_id' );703 724 update_termmeta_cache( $term_ids ); 704 725 } 705 726 706 727 if ( empty( $terms ) ) { 707 728 wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS ); 729 708 730 return array(); 709 731 } 710 732 733 711 734 if ( $child_of ) { 712 735 foreach ( $taxonomies as $_tax ) { 713 736 $children = _get_term_hierarchy( $_tax ); … … 758 781 } 759 782 760 783 $_tt_ids[ $term->term_id ] = 1; 761 $_terms[] = $term;784 $_terms[] = $term; 762 785 } 763 786 764 787 $terms = $_terms; … … 808 831 } 809 832 } 810 833 811 wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS );812 834 813 if ( 'all' === $_fields || 'all_with_object_id' === $_fields ) { 814 $terms = array_map( 'get_term', $terms ); 815 } 835 wp_cache_add( $cache_key, $term_ids, 'terms', DAY_IN_SECONDS ); 836 816 837 817 838 $this->terms = $terms; 839 818 840 return $this->terms; 819 841 } 820 842 -
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;