[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
Tue May 3 02:14:29 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: high | Milestone: 10.3.0
Component: Groups | Version: 10.0.0
Severity: normal | Resolution:
Keywords: has-patch |
--------------------------+---------------------
Comment (by dd32):
Replying to [comment:9 imath]:
> dd32 if it's possible for you to test the patch to see if it's better on
profiles.w.org, that would be cool.
Running [attachment:"8688.patch"] shows it's better, not amazing, but at
least it now completes in seconds rather than minutes.
I initially ran some custom scripts for benchmarking, which were
marginally faster than these builtin BP commands, this is with the 50k
member group (smaller groups are amazingly fast)
Original (similar for removal, this is CLI though so it's got 1G of memory
to play with, and thus doesn't out-of-memory, unlike web requests)
{{{
$ time wp --url=https://profiles.wordpress.org/ bp group member add
--group-id=17 --user-id=14842180
Success: Added user #14842180 to group #17 as member.
real 1m56.373s
user 0m37.416s
sys 0m24.400s
}}}
Patched:
{{{
$ time wp --url=https://profiles.wordpress.org/ bp group member add
--group-id=17 --user-id=14842180
Success: Added user #14842180 to group #17 as member.
real 0m16.247s
user 0m6.788s
sys 0m2.484s
$ time wp --url=https://profiles.wordpress.org/ bp group member remove
--group-id=17 --user-id=14842180
Success: Member #14842180 removed from the group #17.
real 0m14.470s
user 0m6.936s
sys 0m2.344s
}}}
It's obviously much faster for smaller groups:
{{{
$ time wp --url=https://profiles.wordpress.org/ bp group member add
--group-id=55 --user-id=14842180
Success: Added user #14842180 to group #55 as member.
real 0m1.696s
user 0m1.220s
sys 0m0.412s
$ time wp --url=https://profiles.wordpress.org/ bp group member remove
--group-id=55 --user-id=14842180
Success: Member #14842180 removed from the group #55.
real 0m1.673s
user 0m1.284s
sys 0m0.336s
}}}
When adding a single user, this is great, but when calling the function
repeatedly I suspect it'll cause the re-counting to be run for every user.
It might be worth considering something like `wp_defer_term_counting()`,
but it might also be reasonable to just leave that up to plugins / scripts
that are adding/removing many users.
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/8688#comment:10>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list