Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/20/2016 02:42:04 PM (7 years ago)
Author:
dcavins
Message:

Add bp_friends_friendships cache group.

Add friendship caching by the ID of the friendship.
Check the cache before querying for friendship
details in BP_Friends_Friendship::populate.

Update get_user_ids_for_friendship() to create
a new friendship object so it could possibly use
the cached object.

Props dcavins, boonebgorges.

See #6978.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/friends/class-bp-friends-friendship.php

    r9985 r11122  
    148148        $this->assertEquals( 1, $f2->is_confirmed );
    149149    }
     150
     151    /**
     152     * @group friendship_caching
     153     */
     154    public function test_new_bp_friends_friendship_object_should_hit_friendship_object_cache() {
     155        global $wpdb;
     156        $now = time();
     157        $u1 = $this->factory->user->create( array(
     158            'last_activity' => date( 'Y-m-d H:i:s', $now ),
     159        ) );
     160        $u2 = $this->factory->user->create( array(
     161            'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ),
     162        ) );
     163
     164        friends_add_friend( $u1, $u2, true );
     165        $fid = friends_get_friendship_id( $u1, $u2 );
     166
     167        $friendship_obj = new BP_Friends_Friendship( $fid, false, false );
     168        $first_query_count = $wpdb->num_queries;
     169        // Create it again.
     170        $friendship_obj = new BP_Friends_Friendship( $fid, false, false );
     171
     172        $this->assertEquals( $first_query_count, $wpdb->num_queries );
     173    }
    150174}
Note: See TracChangeset for help on using the changeset viewer.