Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/10/2014 08:36:19 PM (12 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-cache.php

    r7619 r8105  
    3232add_action( 'friends_friendship_deleted',  'friends_clear_friend_object_cache' );
    3333
     34/**
     35 * Clear the friend request cache for the user not initiating the friendship.
     36 *
     37 * @since BuddyPress (2.0.0)
     38 *
     39 * @param int $friend_user_id The user ID not initiating the friendship
     40 */
     41function bp_friends_clear_request_cache( $friend_user_id ) {
     42    wp_cache_delete( $friend_user_id, 'bp_friends_requests' );
     43}
     44
     45/**
     46 * Clear the friend request cache when a friendship is saved.
     47 *
     48 * A friendship is deemed saved when a friendship is requested or accepted.
     49 *
     50 * @since BuddyPress (2.0.0)
     51 *
     52 * @param int $friendship_id The friendship ID
     53 * @param int $initiator_user_id The user ID initiating the friendship
     54 * @param int $friend_user_id The user ID not initiating the friendship
     55 */
     56function bp_friends_clear_request_cache_on_save( $friendship_id, $initiator_user_id, $friend_user_id ) {
     57    bp_friends_clear_request_cache( $friend_user_id );
     58}
     59add_action( 'friends_friendship_requested', 'bp_friends_clear_request_cache_on_save', 10, 3 );
     60add_action( 'friends_friendship_accepted',  'bp_friends_clear_request_cache_on_save', 10, 3 );
     61
     62/**
     63 * Clear the friend request cache when a friendship is removed.
     64 *
     65 * A friendship is deemed removed when a friendship is withdrawn or rejected.
     66 *
     67 * @since BuddyPress (2.0.0)
     68 *
     69 * @param int $friendship_id The friendship ID
     70 * @param BP_Friends_Friendship $friendship
     71 */
     72function bp_friends_clear_request_cache_on_remove( $friendship_id, BP_Friends_Friendship $friendship ) {
     73    bp_friends_clear_request_cache( $friendship->friend_user_id ); 
     74}
     75add_action( 'friends_friendship_withdrawn', 'bp_friends_clear_request_cache_on_remove', 10, 2 );
     76add_action( 'friends_friendship_rejected',  'bp_friends_clear_request_cache_on_remove', 10, 2 );
     77
    3478// List actions to clear super cached pages on, if super cache is installed
    3579add_action( 'friends_friendship_rejected',  'bp_core_clear_cache' );
Note: See TracChangeset for help on using the changeset viewer.