Skip to:
Content

BuddyPress.org

Changeset 7700


Ignore:
Timestamp:
12/18/2013 12:01:01 AM (11 years ago)
Author:
johnjamesjacoby
Message:

Remove unnecessary DISTINCT usages from bp-core-classes.php. See #5303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-classes.php

    r7660 r7700  
    246246            case 'online' :
    247247                $this->uid_name = 'user_id';
    248                 $sql['select']  = "SELECT DISTINCT u.{$this->uid_name} as id FROM {$wpdb->usermeta} u";
     248                $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$wpdb->usermeta} u";
    249249                $sql['where'][] = $wpdb->prepare( "u.meta_key = %s", bp_get_user_meta_key( 'last_activity' ) );
    250250                $sql['where'][] = $wpdb->prepare( "u.meta_value >= DATE_SUB( UTC_TIMESTAMP(), INTERVAL %d MINUTE )", apply_filters( 'bp_user_query_online_interval', 15 ) );
     
    260260            case 'random' :
    261261                $this->uid_name = 'user_id';
    262                 $sql['select']  = "SELECT DISTINCT u.{$this->uid_name} as id FROM {$wpdb->usermeta} u";
     262                $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$wpdb->usermeta} u";
    263263                $sql['where'][] = $wpdb->prepare( "u.meta_key = %s", bp_get_user_meta_key( 'last_activity' ) );
    264264
     
    278278            case 'popular' :
    279279                $this->uid_name = 'user_id';
    280                 $sql['select']  = "SELECT DISTINCT u.{$this->uid_name} as id FROM {$wpdb->usermeta} u";
     280                $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$wpdb->usermeta} u";
    281281                $sql['where'][] = $wpdb->prepare( "u.meta_key = %s", bp_get_user_meta_key( 'total_friend_count' ) );
    282282                $sql['orderby'] = "ORDER BY CONVERT(u.meta_value, SIGNED)";
     
    295295                if ( ! bp_disable_profile_sync() || ! bp_is_active( 'xprofile' ) ) {
    296296                    $this->uid_name = 'ID';
    297                     $sql['select']  = "SELECT DISTINCT u.{$this->uid_name} as id FROM {$wpdb->users} u";
     297                    $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$wpdb->users} u";
    298298                    $sql['orderby'] = "ORDER BY u.display_name";
    299299                    $sql['order']   = "ASC";
     
    305305
    306306                    $this->uid_name = 'user_id';
    307                     $sql['select']  = "SELECT DISTINCT u.{$this->uid_name} as id FROM {$bp->profile->table_name_data} u";
     307                    $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$bp->profile->table_name_data} u";
    308308                    $sql['where'][] = "u.field_id = {$fullname_field_id}";
    309309                    $sql['orderby'] = "ORDER BY u.value";
     
    314314                // to infer spam/deleted/non-activated users. To ensure that these users
    315315                // are filtered out, we add an appropriate sub-query.
    316                 $sql['where'][] = "u.{$this->uid_name} IN ( SELECT ID FROM {$wpdb->users} WHERE " . bp_core_get_status_sql( '' ) . " )";
     316                $sql['where'][] = "u.{$this->uid_name} IN ( SELECT id FROM {$wpdb->users} WHERE " . bp_core_get_status_sql( '' ) . " )";
    317317
    318318                break;
     
    321321            default :
    322322                $this->uid_name = 'ID';
    323                 $sql['select']  = "SELECT DISTINCT u.{$this->uid_name} as id FROM {$wpdb->users} u";
     323                $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$wpdb->users} u";
    324324
    325325                // In this case, we assume that a plugin is
     
    438438            $this->total_users = $wpdb->get_var( apply_filters( 'bp_found_user_query', "SELECT FOUND_ROWS()", $this ) );
    439439        } elseif ( 'count_query' == $this->query_vars['count_total'] ) {
    440             $count_select      = preg_replace( '/^SELECT.*?FROM (\S+) u/', "SELECT COUNT(DISTINCT u.{$this->uid_name}) FROM $1 u", $this->uid_clauses['select'] );
     440            $count_select      = preg_replace( '/^SELECT.*?FROM (\S+) u/', "SELECT COUNT(u.{$this->uid_name}) FROM $1 u", $this->uid_clauses['select'] );
    441441            $this->total_users = $wpdb->get_var( apply_filters( 'bp_found_user_query', "{$count_select} {$this->uid_clauses['where']}", $this ) );
    442442        }
     
    872872        $sql = array();
    873873
    874         $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
     874        $sql['select_main'] = "SELECT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
    875875
    876876        if ( 'active' == $type || 'online' == $type || 'newest' == $type  ) {
     
    10141014        }
    10151015
    1016         array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" );
     1016        array_unshift( $sql, "SELECT COUNT(u.ID)" );
    10171017
    10181018        // Get total user results
     
    11321132        $status_sql = bp_core_get_status_sql();
    11331133
    1134         $total_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', "SELECT COUNT(DISTINCT ID) FROM {$wpdb->users} WHERE {$status_sql} AND ID IN ({$user_ids})" );
    1135         $paged_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', "SELECT DISTINCT ID as id, user_registered, user_nicename, user_login, user_email FROM {$wpdb->users} WHERE {$status_sql} AND ID IN ({$user_ids}) {$pag_sql}" );
     1134        $total_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', "SELECT COUNT(ID) FROM {$wpdb->users} WHERE {$status_sql} AND ID IN ({$user_ids})" );
     1135        $paged_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', "SELECT ID as id, user_registered, user_nicename, user_login, user_email FROM {$wpdb->users} WHERE {$status_sql} AND ID IN ({$user_ids}) {$pag_sql}" );
    11361136
    11371137        $total_users = $wpdb->get_var( $total_users_sql );
Note: See TracChangeset for help on using the changeset viewer.