Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/20/2016 02:42:15 PM (8 years ago)
Author:
dcavins
Message:

Use new function BP_Friends_Friendships::get_friendships().

Take advantage of the caching introduced
in BP_Friends_Friendships::get_friendships()
by using get_friendships() as the underlying function in
get_friend_user_ids(), get_friendship_id(), total_friend_count(),
check_is_friend(),
and delete_all_for_user().

Props dcavins, boonebgorges.

Fixes #6978.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/bp-friends-filters.php

    r10417 r11124  
    2929
    3030    // Stop if user isn't logged in.
    31     if ( ! is_user_logged_in() ) {
     31    if ( ! $user_id = bp_loggedin_user_id() ) {
    3232        return;
    3333    }
    3434
    35     $bp = buddypress();
     35    $maybe_friend_ids = wp_parse_id_list( $user_ids_sql );
    3636
    37     // Fetch whether or not the user is a friend of the current user.
    38     $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_sql} ) ) OR (initiator_user_id IN ( {$user_ids_sql} ) AND friend_user_id = %d )", bp_loggedin_user_id(), bp_loggedin_user_id() ) );
    39 
    40     // Keep track of members that have a friendship status with the current user.
    41     $friend_user_ids = array();
    42 
    43     // The "friend" is the user ID in the pair who is *not* the logged in user.
    44     foreach ( (array) $friend_status as $fs ) {
    45         $friend_id = bp_loggedin_user_id() == $fs->initiator_user_id ? $fs->friend_user_id : $fs->initiator_user_id;
    46         $friend_user_ids[] = $friend_id;
    47 
    48         if ( isset( $user_query->results[ $friend_id ] ) ) {
    49             if ( 0 == $fs->is_confirmed ) {
    50                 $status = $fs->initiator_user_id == bp_loggedin_user_id() ? 'pending' : 'awaiting_response';
    51             } else {
    52                 $status = 'is_friend';
    53             }
    54 
    55             $user_query->results[ $friend_id ]->is_friend         = $fs->is_confirmed;
    56             $user_query->results[ $friend_id ]->friendship_status = $status;
    57         }
    58     }
    59 
    60     // The rest are not friends with the current user, so set status accordingly.
    61     $not_friends = array_diff( $user_query->user_ids, $friend_user_ids );
    62     foreach ( (array) $not_friends as $nf ) {
    63         if ( bp_loggedin_user_id() == $nf ) {
    64             continue;
    65         }
    66 
    67         if ( isset( $user_query->results[ $nf ] ) ) {
    68             $user_query->results[ $nf ]->friendship_status = 'not_friends';
     37    foreach ( $maybe_friend_ids as $friend_id ) {
     38        $status = BP_Friends_Friendship::check_is_friend( $user_id, $friend_id );
     39        $user_query->results[ $friend_id ]->friendship_status = $status;
     40        if ( 'is_friend' == $status ) {
     41            $user_query->results[ $friend_id ]->is_friend = 1;
    6942        }
    7043    }
Note: See TracChangeset for help on using the changeset viewer.