Make WordPress Core


Ignore:
Timestamp:
09/06/2010 08:09:41 AM (16 years ago)
Author:
scribu
Message:

Rewrite WP_User_Query to use JOIN instead of subquery. See #14572

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/user.php

    r15574 r15579  
    464464                $meta_queries[] = wp_array_slice_assoc( $qv, array( 'meta_key', 'meta_value', 'meta_compare' ) );
    465465
    466                 $meta_query_sql = _wp_meta_sql( $meta_queries, 'user_id', $wpdb->usermeta );
     466                $meta_query_sql = _wp_meta_sql( $meta_queries, 'user_id' );
    467467
    468468                if ( !empty( $meta_query_sql ) ) {
    469                         $this->query_where .= " AND $wpdb->users.ID IN ($meta_query_sql)";
     469                        $this->query_from .= " INNER JOIN $wpdb->usermeta ON ($wpdb->users.ID = $wpdb->usermeta.user_id)";
     470                        $this->query_where .= $meta_query_sql;
    470471                }
    471472
    … …  
    491492                global $wpdb;
    492493
    493                 $this->results = $wpdb->get_col("SELECT DISTINCT($wpdb->users.ID)" . $this->query_from . $this->query_where . $this->query_orderby . $this->query_limit);
     494                $this->results = $wpdb->get_col("SELECT $wpdb->users.ID" . $this->query_from . $this->query_where . $this->query_orderby . $this->query_limit);
    494495
    495496                if ( !$this->results )
    … …  
    497498
    498499                if ( $this->query_vars['count_total'] )
    499                         $this->total_users = $wpdb->get_var("SELECT COUNT(DISTINCT($wpdb->users.ID))" . $this->query_from . $this->query_where);
     500                        $this->total_users = $wpdb->get_var("SELECT COUNT($wpdb->users.ID)" . $this->query_from . $this->query_where);
    500501
    501502                if ( 'all' == $this->query_vars['fields'] ) {
Note: See TracChangeset for help on using the changeset viewer.