Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/27/2018 01:29:33 PM (7 years ago)
Author:
dcavins
Message:

Change check in BP_Friends_Friendship::check_is_friend().

In BP2.5, we introduced a new friendship caching mechanism that created a new cache item containing all of a user's friendships. This approach worked well on sites with fewer friendships per user, but caused cache access issues on sites with lots of friendship connections.

This update replaces the cache-intensive change to BP_Friends_Friendship::check_is_friend() with a return to a single lookup to determine friendship status between two users. To minimize SQL lookups, individual friendships are now cached, and a new cache-warming function has been added to bulk update these new cache items: BP_Friends_Friendship::update_bp_friends_cache().

Props januzi_pl, boonebgorges, r-a-y, djpaul, dcavins.

Fixes #7436.

File:
1 edited

Legend:

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

    r11123 r11865  
    120120add_action( 'friends_friendship_rejected',  'bp_friends_clear_request_cache_on_remove', 10, 2 );
    121121
     122/**
     123 * Delete individual friendships from the cache when they are changed.
     124 *
     125 * @since 3.0.0
     126 *
     127 * @param BP_Friends_Friendship $friendship Friendship object.
     128 */
     129function bp_friends_delete_cached_friendships_on_friendship_save( $friendship ) {
     130    bp_core_delete_incremented_cache( $friendship->friend_user_id . ':' . $friendship->initiator_user_id, 'bp_friends' );
     131    bp_core_delete_incremented_cache( $friendship->initiator_user_id . ':' . $friendship->friend_user_id, 'bp_friends' );
     132}
     133add_action( 'friends_friendship_after_save', 'bp_friends_delete_cached_friendships_on_friendship_save' );
     134
    122135// List actions to clear super cached pages on, if super cache is installed.
    123136add_action( 'friends_friendship_rejected',  'bp_core_clear_cache' );
Note: See TracChangeset for help on using the changeset viewer.