[buddypress-trac] [BuddyPress Trac] #7436: Very slow check_is_friend function

buddypress-trac noreply at wordpress.org
Mon Feb 6 15:02:58 UTC 2017


#7436: Very slow check_is_friend function
--------------------------+--------------------
 Reporter:  januzi_pl     |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  low           |   Milestone:  2.7.5
Component:  Friends       |     Version:
 Severity:  major         |  Resolution:
 Keywords:                |
--------------------------+--------------------

Comment (by boonebgorges):

 @januzi_pl - Thanks so much for the quick reply. A note for anyone
 downloading it: change the file extension to .gz and use gunzip - it's not
 a regular zip file.

 The log shows that `BP_Friends_Friendship::check_is_friend()` ->
 `BP_Friends_Friendship::get_friendships()` is called 19 times, which
 sounds correct for a member directory (20 members, one of whom is the
 logged-in user, and doesn't need a friend check). The log then shows that
 `get_friendships()` calls `BP_Friends_Friendship::__construct()` 218,196
 times, which clearly does *not* sound correct. See
 https://buddypress.trac.wordpress.org/browser/tags/2.7.4/src/bp-
 friends/classes/class-bp-friends-friendship.php?marks=261,268,289#L242 for
 the relevant function calls that should result in a cache hit.

 It looks like `bp_get_non_cached_ids()` calls `wp_cache_get()` a huge
 number of times (218,204). I'm guessing this means that the following call
 is returning an incorrect value of some sort:

 {{{
 $friendship_ids = wp_cache_get( $user_id,
 'bp_friends_friendships_for_user' );
 }}}

 If `$friendship_ids` mistakenly ends up returning an enormous array (the
 numbers suggest it's got about 11,400 members), it would cause the kind of
 cache I/O that you've cited.

 @januzi_pl You noted that this is a fairly small site, which I'm guessing
 means that no user legitimately has 11,400 friends. Can you check to see
 what's being returned from line 261 here
 https://buddypress.trac.wordpress.org/browser/tags/2.7.4/src/bp-
 friends/classes/class-bp-friends-friendship.php?marks=261,268,289#L242?
 That might help us figure out what's going on. Also, if you are running a
 cache dropin (wp-content/object-cache.php), please share the details about
 which dropin it is, and what your cache backend is (Memcached, etc).

 As a side note, cache multi-get support in WP would help us to mitigate
 this problem in cases where a user really *did* have many thousands of
 friends, at least in cases where the cache backend supports true multi-
 get. See https://core.trac.wordpress.org/ticket/20875

 cc @dcavins

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7436#comment:3>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list