Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/18/2022 05:32:26 AM (3 years ago)
Author:
imath
Message:

Improve group members count query performance

[13103] introduced a change in 10.0.0 that can be very time consuming when a group has a lot of members.

To keep the main improvements of the referenced commit (only refreshing group members count when a user joins or leaves a group) but optimize queries performance, we are introducing a new way to count group members in the BP_Group_Member_Query.

We are also introducing a way to defer group members count when adding a batch of members to a group. Using bp_groups_defer_group_members_count() avoids to refresh the count each time a member of this batch is added. For more information about how to use this function, you can have a look at how BuddyPress is using it into src/bp-groups/bp-groups-admin.php.

Props dd32, espellcaste

See #8688 (trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-member.php

    r13103 r13280  
    310310        self::refresh_total_group_count_for_user( $this->user_id );
    311311
    312         // Update the group's member count.
    313         self::refresh_total_member_count_for_group( $this->group_id );
    314 
    315312        /**
    316313         * Fires after the current group membership item has been saved.
     
    448445        self::refresh_total_group_count_for_user( $this->user_id );
    449446
    450         // Update the group's member count.
    451         self::refresh_total_member_count_for_group( $this->group_id );
    452 
    453447        /**
    454448         * Fires after a member is removed from a group.
     
    517511        // Update the user's group count.
    518512        self::refresh_total_group_count_for_user( $user_id );
    519 
    520         // Update the group's member count.
    521         self::refresh_total_member_count_for_group( $group_id );
    522513
    523514        /**
Note: See TracChangeset for help on using the changeset viewer.