diff --git src/bp-friends/classes/class-bp-friends-friendship.php src/bp-friends/classes/class-bp-friends-friendship.php
index f683214e5..eb1aea25f 100644
|
|
class BP_Friends_Friendship { |
603 | 603 | return 'not_friends'; |
604 | 604 | } |
605 | 605 | |
606 | | /* |
607 | | * Find friendships where the possible_friend_userid is the |
608 | | * initiator or friend. |
609 | | */ |
610 | | $args = array( |
611 | | 'initiator_user_id' => $possible_friend_userid, |
612 | | 'friend_user_id' => $possible_friend_userid |
613 | | ); |
614 | | $result = self::get_friendships( $initiator_userid, $args, 'OR' ); |
| 606 | $cache_key_1 = $initiator_userid . ':' . $possible_friend_userid; |
| 607 | $cache_key_2 = $possible_friend_userid . ':' . $initiator_userid; |
615 | 608 | |
616 | | if ( $result ) { |
617 | | $friendship = current( $result ); |
618 | | if ( ! $friendship->is_confirmed ) { |
619 | | $status = $initiator_userid == $friendship->initiator_user_id ? 'pending' : 'awaiting_response'; |
| 609 | $cached = bp_core_get_incremented_cache( $cache_key_1, 'friends' ); |
| 610 | if ( false === $cached ) { |
| 611 | $cached = bp_core_get_incremented_cache( $cache_key_2, 'friends' ); |
| 612 | } |
| 613 | |
| 614 | if ( false === $cached ) { |
| 615 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT id, initiator_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id = %d) OR (initiator_user_id = %d AND friend_user_id = %d)", $initiator_userid, $possible_friend_userid, $possible_friend_userid, $initiator_userid ) ); |
| 616 | |
| 617 | if ( ! empty( $result ) ) { |
| 618 | if ( 0 == (int) $result[0]->is_confirmed ) { |
| 619 | $status = $initiator_userid == $result[0]->initiator_user_id ? 'pending' : 'awaiting_response'; |
| 620 | } else { |
| 621 | $status = 'is_friend'; |
| 622 | } |
620 | 623 | } else { |
621 | | $status = 'is_friend'; |
| 624 | $status = 'not_friends'; |
622 | 625 | } |
| 626 | |
| 627 | bp_core_set_incremented_cache( $cache_key_1, 'friends', $status ); |
623 | 628 | } else { |
624 | | $status = 'not_friends'; |
| 629 | $status = $cached; |
625 | 630 | } |
626 | 631 | |
627 | 632 | return $status; |