Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/14/2014 06:49:55 PM (10 years ago)
Author:
r-a-y
Message:

Check BP_User_Query when using friends_check_friendship_status().

Previously, friends_check_friendship_status() did not reference the data
already queried in the members loop via BP_User_Query. As a result, if
a user was logged in and viewing the member directory, this added twenty
additional DB queries to the page.

This commit:

  • Adds an additional property - friendship_status - to bp_friends_filter_user_query_populate_extras(). This property references the various friendship statuses from BP_Friends_Friendship::check_is_friend()
  • Checks this new property in friends_check_friendship_status() before querying the DB
  • Adds unit tests

Props r-a-y, boonebgorges.

Fixes #5703.

File:
1 edited

Legend:

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

    r7999 r8514  
    3939
    4040        if ( isset( $user_query->results[ $friend_id ] ) ) {
    41             $user_query->results[ $friend_id ]->is_friend = $fs->is_confirmed;
     41            if ( 0 == $fs->is_confirmed ) {
     42                $status = $fs->initiator_user_id == bp_loggedin_user_id() ? 'pending' : 'awaiting_response';
     43            } else {
     44                $status = 'is_friend';
     45            }
     46
     47            $user_query->results[ $friend_id ]->is_friend         = $fs->is_confirmed;
     48            $user_query->results[ $friend_id ]->friendship_status = $status;
    4249        }
    4350    }
Note: See TracChangeset for help on using the changeset viewer.