Opened 10 years ago
Closed 10 years ago
#5815 closed defect (bug) (fixed)
bp_blogs_total_blogs_for_user() queries database on each page view in multisite
Reported by: | wpdennis | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 2.1 | Priority: | normal |
Severity: | normal | Version: | 1.2 |
Component: | Blogs | Keywords: | has-patch commit |
Cc: |
Description
bp_blogs_total_blogs_for_user() gets triggered by BP_Blogs_Component->setup_nav() in multisite environments.
If the visitor isn't logged in, this is resulting in a database query on each page view. The caching fails, since the result for logged out users is always 0:
if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
Maybe bp_blogs_total_blogs_for_user() could return 0 if the current user isn't logged in:
if (!is_user_logged_in()) return 0;
And/or the caching condition should be:
if ( false === $count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
Attachments (2)
Change History (7)
#2
@
10 years ago
- Keywords has-patch added; dev-feedback removed
- Milestone changed from Awaiting Review to 2.1
- Version set to 1.2
wpdennis: Always love your tickets relating performance!
Confirmed. Going to try and sneak this in to 2.1.
#3
@
10 years ago
We also need to add the strict type check, in case a legitimately logged-in user has 0 blogs - we don't want that to result in a cache miss.
Something like this seems to work: