Skip to:
Content

BuddyPress.org

Ticket #6193: 6193.patch

File 6193.patch, 975 bytes (added by imath, 5 years ago)
  • src/bp-members/bp-members-cache.php

    diff --git src/bp-members/bp-members-cache.php src/bp-members/bp-members-cache.php
    index 4cfff86..9e44601 100644
    function bp_members_prefetch_member_type( BP_User_Query $bp_user_query ) { 
    2121        ) );
    2222
    2323        $cached_member_ids = array();
    24         foreach ( $member_types as $member_type ) {
    25                 wp_cache_set( $member_type->object_id, $member_type->name, 'bp_member_type' );
    26                 $cached_member_ids[] = $member_type->object_id;
     24
     25        // First get an array of users
     26        $user_ids = array_unique( wp_list_pluck( $member_types, 'object_id' ) );
     27
     28        // Then cache all different member types for a user
     29        foreach ( $user_ids as $user_id ) {
     30                $types = array_values( wp_filter_object_list( $member_types, array( 'object_id' => $user_id ), 'and', 'name' ) );
     31                wp_cache_set( $user_id, $types, 'bp_member_type' );
     32                $cached_member_ids[] = $user_id;
    2733        }
    2834
    2935        // Cache an empty value for users with no type.