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 | 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:
- Turn on object caching.
- Change the members directory page slug to something else.
- Navigate to the Members Directory page.
- Hover over a member permalink in the member loop.
- 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)
Change History (8)
#2
@
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
@
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
@
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? :)
Let me know if you think this approach is okay.