Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/09/2021 02:01:40 PM (4 years ago)
Author:
espellcaste
Message:

Improving the group member count routine and the function helper.

The group member count routine was updated to avoid direct, uncached, SQL query and unnecessary cache refresh when a group's Members page was viewed.

is now being used to get the group member count which takes into account users' existence in the site,

the query is now cached and filterable.

was also updated to get the current group from if available.

Props imath
Fixes #7614 and see #6749

File:
1 edited

Legend:

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

    r13097 r13103  
    466466
    467467    /**
    468      * Refresh the total_group_count for a user.
     468     * Refresh the `total_group_count` for a user.
    469469     *
    470470     * @since 1.8.0
    471471     *
    472472     * @param int $user_id ID of the user.
    473      * @return bool True on success, false on failure.
    474473     */
    475474    public static function refresh_total_group_count_for_user( $user_id ) {
    476         return bp_update_user_meta( $user_id, 'total_group_count', (int) self::total_group_count( $user_id ) );
    477     }
    478 
    479     /**
    480      * Refresh the total_member_count for a group.
     475        bp_update_user_meta( $user_id, 'total_group_count', (int) self::total_group_count( $user_id ) );
     476    }
     477
     478    /**
     479     * Refresh the `total_member_count` for a group.
     480     *
     481     * The request skip the current cache so that we always grab the lastest total count.
    481482     *
    482483     * @since 1.8.0
     484     * @since 10.0.0 Updated to use `BP_Groups_Group::get_total_member_count`
    483485     *
    484486     * @param int $group_id ID of the group.
    485      * @return bool|int True on success, false on failure.
    486487     */
    487488    public static function refresh_total_member_count_for_group( $group_id ) {
    488         return groups_update_groupmeta( $group_id, 'total_member_count', (int) BP_Groups_Group::get_total_member_count( $group_id ) );
     489        BP_Groups_Group::get_total_member_count( $group_id, true );
    489490    }
    490491
     
    496497     * @param int $user_id  ID of the user.
    497498     * @param int $group_id ID of the group.
    498      * @return True on success, false on failure.
     499     * @return bool True on success, false on failure.
    499500     */
    500501    public static function delete( $user_id, $group_id ) {
     
    511512        do_action( 'bp_groups_member_before_delete', $user_id, $group_id );
    512513
    513         $bp = buddypress();
     514        $bp     = buddypress();
    514515        $remove = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
    515516
     
    530531        do_action( 'bp_groups_member_after_delete', $user_id, $group_id );
    531532
    532         return $remove;
     533        return (bool) $remove;
    533534    }
    534535
Note: See TracChangeset for help on using the changeset viewer.