Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/21/2011 10:27:09 PM (13 years ago)
Author:
djpaul
Message:

Tune up 'for' loops. Fixes #2985, props cnorris23 and r-a-y

File:
1 edited

Legend:

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

    r4709 r4770  
    510510        if ( bp_is_active( 'xprofile' ) && 'alphabetical' != $type ) {
    511511            $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", bp_xprofile_fullname_field_name() ) );
    512             for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     512            for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    513513                foreach ( (array)$names as $name ) {
    514514                    if ( $name->id == $paged_users[$i]->id )
     
    521521        if ( 'popular' != $type ) {
    522522            $friend_count = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as total_friend_count FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'total_friend_count' ) ) );
    523             for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     523            for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    524524                foreach ( (array)$friend_count as $count ) {
    525525                    if ( $count->id == $paged_users[$i]->id )
     
    532532        if ( bp_is_active( 'friends' ) ) {
    533533            $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", $bp->loggedin_user->id, $bp->loggedin_user->id ) );
    534             for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     534            for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    535535                foreach ( (array)$friend_status as $status ) {
    536536                    if ( $status->initiator_user_id == $paged_users[$i]->id || $status->friend_user_id == $paged_users[$i]->id )
     
    542542        if ( 'active' != $type ) {
    543543            $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) );
    544             for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     544            for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    545545                foreach ( (array)$user_activity as $activity ) {
    546546                    if ( $activity->id == $paged_users[$i]->id )
     
    553553        if ( 'active' != $type ) {
    554554            $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) );
    555             for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     555            for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    556556                foreach ( (array)$user_activity as $activity ) {
    557557                    if ( $activity->id == $paged_users[$i]->id )
     
    563563        // Fetch the user's latest update
    564564        $user_update = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as latest_update FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'bp_latest_update' ) ) );
    565         for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     565        for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    566566            foreach ( (array)$user_update as $update ) {
    567567                if ( $update->id == $paged_users[$i]->id )
Note: See TracChangeset for help on using the changeset viewer.