Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/23/2015 01:39:05 AM (9 years ago)
Author:
boonebgorges
Message:

Use 'bp_member_member_type' as the member type cache bucket name.

Using 'bp_member_type' was creating the potential for collisions between WP's
taxonomy cache (which uses the taxonomy name 'bp_member_type' and term IDs as
cache keys) and BP's per-member member type cache (which uses the bucket
'bp_member_type' and user IDs as cache keys). The collisions take place only
when there is a 'bp_member_type' term ID that overlaps with a user ID.

The new cache group 'bp_member_member_type' is chosen to underscore that what's
being cached is the relationship between individual members and the user types
to which they belong.

Props imath, johnjamesjacoby.
Fixes #6242.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/members/types.php

    r9486 r9533  
    206206        $this->assertFalse( bp_get_member_type( $u ) );
    207207    }
     208
     209    /**
     210     * @group BP6242
     211     * @group cache
     212     */
     213    public function test_bp_get_member_type_should_not_conflict_with_term_cache() {
     214        global $wpdb;
     215
     216        // Offset IDs.
     217        $dummy_terms = $this->factory->tag->create_many( 5 );
     218
     219        $u1 = $this->factory->user->create();
     220        bp_register_member_type( 'foo' );
     221        bp_set_member_type( $u1, 'foo' );
     222
     223        // Fetch a term ID.
     224        $terms = get_terms( 'bp_member_type', array( 'hide_empty' => false, 'fields' => 'all' ) );
     225
     226        // Make sure the user's ID matches a term ID, to force a cache confusion.
     227        $u2 = $this->factory->user->create();
     228        $new_user_id = $terms[0]->term_id;
     229        $wpdb->update( $wpdb->users, array( 'ID' => $new_user_id ), array( 'ID' => $u2 ) );
     230
     231        bp_set_member_type( $new_user_id, 'foo' );
     232
     233        // Reprime the taxonomy cache.
     234        $terms = get_terms( 'bp_member_type', array( 'hide_empty' => false, 'fields' => 'all' ) );
     235
     236        $this->assertSame( 'foo', bp_get_member_type( $new_user_id, true ) );
     237    }
    208238}
Note: See TracChangeset for help on using the changeset viewer.