Skip to:
Content

BuddyPress.org

Opened 11 years ago

Closed 11 years ago

#5402 closed defect (bug) (fixed)

Object cache - bp_core_get_user_domain() issue

Reported by: r-a-y's profile r-a-y Owned by:
Milestone: 2.0 Priority: normal
Severity: normal Version:
Component: Core Keywords: has-patch commit
Cc:

Description

Issue: When object cache is enabled and you change the members directory page slug to something else, the member permalink references the older member page slug and not the newer one.

Steps to duplicate:

  1. Turn on object caching.
  2. Change the members directory page slug to something else.
  3. Navigate to the Members Directory page.
  4. Hover over a member permalink in the member loop.
  5. The member permalink references the older members directory page slug and not the newer one.

Problem: bp_core_get_user_domain() has its own object cache, which is impossible to clear because it is keyed to each individual user.

We shouldn't be caching the user domain as we are already caching the username lookup, which is the most intensive part of this function to begin with. Therefore, the attached patch removes the object cache for bp_core_get_user_domain() and leaves the pre_cache filter in place for backpat.

Attachments (1)

5402.01.patch (1.8 KB) - added by r-a-y 11 years ago.

Download all attachments as: .zip

Change History (8)

@r-a-y
11 years ago

#1 @r-a-y
11 years ago

  • Keywords has-patch added

Let me know if you think this approach is okay.

Last edited 11 years ago by r-a-y (previous) (diff)

#2 @boonebgorges
11 years ago

  • Keywords commit added

We shouldn't be caching the user domain as we are already caching the username lookup, which is the most intensive part of this function to begin with

Good call. This seems right to me. Unit tests would be nice :) but otherwise make it so.

#3 @r-a-y
11 years ago

Unit tests would be nice :)

I'd do this if I knew how to add an object cache to run with unit tests or how to mock an object cache for unit tests.

Any pointers?

#4 @boonebgorges
11 years ago

You don't need to mock a persistent cache, since our unit tests all take place in the same pageload anyway. You can test that things are getting invalidated by doing a before-and-after test - a functional test:

public function test_bp_core_get_user_domain_after_directory_page_change() {
    $u = $this->create_user();

    $pages = bp_core_get_directory_pages();
    $members_page = get_post( $pages->members->ID );
    $members_page->post_name = 'new-members-slug';
    wp_update_post( $members_page );

    $user = new WP_User( $u );

    $this->assertSame( home_url( 'new-members-slug' ) . '/' . $user->user_nicename . '/', bp_core_get_user_domain( $u ) );
}

I wrote that off the top of my head so it may not work as-is, but you get the idea? :)

#5 @r-a-y
11 years ago

Gotcha, ol' wise one!

#6 @r-a-y
11 years ago

In 7910:

Add unit test to check bp_core_get_user_domain() after changing the
members directory page slug.

See #5402.

Props boonebgorges.

#7 @r-a-y
11 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in r7911.

I guess I shouldn't use trailing periods in commit messages!

Note: See TracTickets for help on using tickets.