Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/27/2018 01:29:33 PM (9 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/tests/phpunit/testcases/friends/functions.php

    r11737 r11865  
    283283         * @group friendship_caching
    284284         */
    285         public function test_friends_check_friendship_should_hit_user_cache() {
    286                 global $wpdb;
    287                 $now = time();
    288                 $u1 = self::factory()->user->create( array(
    289                         'last_activity' => date( 'Y-m-d H:i:s', $now ),
    290                 ) );
    291                 $u2 = self::factory()->user->create( array(
    292                         'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ),
    293                 ) );
    294                 $u3 = self::factory()->user->create( array(
    295                         'last_activity' => date( 'Y-m-d H:i:s', $now - 200 ),
    296                 ) );
    297 
    298                 friends_add_friend( $u1, $u2, true );
    299                 friends_add_friend( $u1, $u3, false );
    300 
    301                 friends_check_friendship_status( $u1, $u2 );
    302                 $first_query_count = $wpdb->num_queries;
    303 
    304                 friends_check_friendship_status( $u1, $u3 );
    305 
    306                 $this->assertEquals( $first_query_count, $wpdb->num_queries );
    307         }
    308 
    309         /**
    310          * @group friendship_caching
    311          */
    312285        public function test_friends_check_friendship_should_hit_friendship_object_cache() {
    313286                global $wpdb;
    … …  
    326299
    327300                /*
    328                  * We expect this to generate one query to find $u2's friendships,
    329                  * but the friendship object itself should come from cache.
     301                 * This should access the previous friendship check's cached items.
    330302                 */
    331303                friends_check_friendship_status( $u2, $u1 );
    332304
    333                 $this->assertEquals( $first_query_count + 1, $wpdb->num_queries );
     305                $this->assertEquals( $first_query_count, $wpdb->num_queries );
    334306        }
    335307
Note: See TracChangeset for help on using the changeset viewer.