Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/10/2014 08:36:19 PM (11 years ago)
Author:
r-a-y
Message:

Cache the friendship request user IDs for a given user.

This commit:

  • Caches calls to BP_Friends_Friendship::get_friendship_request_user_ids()
  • Invalidates the friend request cache when a friendship is saved or removed
  • Adds unit tests

See #5435, #5414

File:
1 edited

Legend:

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

    r7860 r8105  
    227227     */
    228228    public static function get_friendship_request_user_ids( $user_id ) {
    229         global $wpdb, $bp;
    230 
    231         return $wpdb->get_col( $wpdb->prepare( "SELECT initiator_user_id FROM {$bp->friends->table_name} WHERE friend_user_id = %d AND is_confirmed = 0", $user_id ) );
     229        $friend_requests = wp_cache_get( $user_id, 'bp_friends_requests' );
     230
     231        if ( false === $friend_requests ) {
     232            global $wpdb, $bp;
     233
     234            $friend_requests = $wpdb->get_col( $wpdb->prepare( "SELECT initiator_user_id FROM {$bp->friends->table_name} WHERE friend_user_id = %d AND is_confirmed = 0", $user_id ) );
     235
     236            wp_cache_set( $user_id, $friend_requests, 'bp_friends_requests' );
     237        }
     238
     239        return $friend_requests;
    232240    }
    233241
Note: See TracChangeset for help on using the changeset viewer.