[buddypress-trac] [BuddyPress Trac] #8688: BP_Groups_Group::get_total_member_count() is highly inefficient, and runs out of memory

buddypress-trac noreply at wordpress.org
Wed Apr 27 10:29:06 UTC 2022


#8688: BP_Groups_Group::get_total_member_count() is highly inefficient, and runs
out of memory
--------------------------+-----------------------------
 Reporter:  dd32          |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Groups        |    Version:
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 When adding/removing a user to a group,
 `BP_Groups_Member::refresh_total_member_count_for_group()` is called which
 is designed to update the member count for the group.

 It quickly calls `BP_Groups_Group::get_total_member_count()` only for it
 to then call `groups_get_group_members()` which loads all the `WP_User`
 objects and XProfile data for those users. This quickly exhausts all PHP
 memory.

 On WordPress.org, we've run into this with a group of 50,000 members.
 Although I suspect we ran past this limitation back at 40k users.

 The resulting SQL query generated by `BP_Group_Member_Query` to fetch &
 order the WP_User objects is over 800,000 characters long..

 A PR is attached, which is a bit hacky IMHO, but seemingly does the job by
 avoiding the WP_User querying, but it's done by using a non-standard and
 quirks of `BP_Group_Member_Query`. Ideally, perhaps the code path for
 "Just get me a count of the users in this group" could be optimised within
 `BP_Group_Member_Query`.

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/8688>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list