#4908 closed defect (bug) (fixed)
Avoid switch_to_blog in bp_core_fetch_avatar
Reported by: | wpdennis | Owned by: | |
---|---|---|---|
Milestone: | 1.7 | Priority: | high |
Severity: | normal | Version: | 1.7 |
Component: | Core | Keywords: | dev-feedback |
Cc: |
Description
In a multisite installation with buddypress enabled (network wide) every get_avatar() triggers a switch_to_blog() on child sites.
The reason is the check, whether avatars are activated:
if ( ! bp_get_option( 'show_avatars' ) ) return;
in http://buddypress.trac.wordpress.org/browser/trunk/bp-core/bp-core-avatars.php#L96
bp_get_option() forces the switch_to_blog() to get the option from the root blog for every avatar. I don't see a way to avoid this in current version.
Can we add a simple check for a constant like "BP_AVATAR_ENABLED" or something to give the chance to avoid this bp_get_option() - call?
Change History (5)
#1
@
12 years ago
- Milestone changed from Awaiting Review to 1.7
- Priority changed from normal to high
- Type changed from enhancement to defect (bug)
- Version set to 1.7
#2
@
12 years ago
- Resolution set to fixed
- Status changed from new to closed
For some reason, my commit message didn't autoclose this ticket. Hm.
Fixed in r6881.
#3
@
12 years ago
Hey boone,
thank you. In combination with bbpress <2.3 there are a multiple of db requests per avatar, because it hooks bbp_set_current_user_default() to switch_to_blog(). I think it will change with 2.3 but I'm not sure here.
But besides that, even with object cache there will be still one switch_to_blog() on each page view. Maybe you can consider to provide a constant like BP_AVATAR_ENABLED for the wp-config.php, because it's a really "constant" behaviour in each network.
Something like:
$bp->avatar->show_avatars = (defined('BP_AVATAR_ENABLED') && is_bool(BP_AVATAR_ENABLED)) ? BP_AVATAR_ENABLED : (bool) bp_get_option( 'show_avatars' );
I would love to have the opportunity to avoid any queries with switch_to_blog(), especially for something that (nearly) never changes. What do you think?
Thanks for the report, wpdennis. Confirmed.
This is a regression for 1.7. See http://buddypress.trac.wordpress.org/changeset/6468
It wouldn't be a huge problem, if not for the refactor of
get_blog_option()
in WP that changed it to useswitch_to_blog()
.Anyway, this problem is likely to cause severe performance problems on non-root blogs, and as I said it's a regression from 1.6, so I'm going to recommend that we take care of it in 1.7. I will write a patch in a few moments.