Skip to:
Content

BuddyPress.org

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#4908 closed defect (bug) (fixed)

Avoid switch_to_blog in bp_core_fetch_avatar

Reported by: wpdennis's profile 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 @boonebgorges
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

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 use switch_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.

#2 @boonebgorges
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 @wpdennis
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?

#4 @boonebgorges
12 years ago

OK, that's a reasonable request.

#5 @boonebgorges
12 years ago

(In [6884]) Introduces BP_SHOW_AVATARS constant

This constant allows admins of advanced MS setups to avoid a potentially
costly call to bp_get_option( 'show_avatar' )

Fixes #4908

Props wpdennis

Note: See TracTickets for help on using tickets.