Make WordPress Core

Changeset 15579


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

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

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r15574 r15579  
    42454245 * @param array $queries An array of queries
    42464246 * @param string $meta_id_column The column that holds the object id
    4247  * @param string $table Which meta table to look in
    42484247 * @return string
    42494248 */
    4250 function _wp_meta_sql( $queries, $meta_id_column, $table ) {
     4249function _wp_meta_sql( $queries, $meta_id_column ) {
    42514250    global $wpdb;
    42524251
     
    42794278
    42804279    return "
    4281         SELECT $meta_id_column
    4282         FROM $table
    4283         WHERE CASE meta_key
     4280        AND CASE meta_key
    42844281        " . implode( "\n", $clauses ) . "
    42854282        END
  • 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.