[buddypress-trac] [BuddyPress] #4913: BP_Core->setup_globals is very expensive on child sites in a network (switch_to_blog())

buddypress-trac noreply at wordpress.org
Wed Apr 3 13:40:47 UTC 2013


#4913: BP_Core->setup_globals is very expensive on child sites in a network
(switch_to_blog())
-------------------------+-----------------------------
 Reporter:  wpdennis     |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Core         |    Version:
 Severity:  normal       |   Keywords:  dev-feedback
-------------------------+-----------------------------
 In a network with BuddyPress enabled network wide, ''setup_globals()''
 forces multiple ''switch_to_blog()'' on each page view on a child site,
 because of bp_get_option(). With things like bbpress (<2.3) this results
 in a lot (!) of db queries.

 I reduced the load a little by adding this snippet in a ms plugin:

 {{{
 add_action('bp_init', function() {
         global $bp;
         if (empty($bp->root_domain))
                 $bp->root_domain = 'http://www.example.com';

         if (1 != get_current_blog_id() and empty($bp->pages))
                 $bp->pages = true; // not needed on child sites
 }, 2);
 }}}

 But I'm not sure if it's too custom and maybe it's only working in my
 case. Four questions here:

 1) Are there possible installations where you need things like $bp->pages
 on a child site while BuddyPress is network wide activated? If not, can we
 check this in setup_globals() and don't load $pages at all?

 2) Can we add a constant like BP_ROOT_DOMAIN (for wp-config.php) to avoid
 ''bp_core_get_root_domain()'' on each page view for such a constant value?

 3) Is it possible to use object cache for bp_core_get_root_options()? I'm
 not sure if cache invalidation is trivial in this case. Is there a central
 function which updates the options? If so, we can do it in like 5 lines of
 code and store the value in a global group.

 4) ''bp_update_is_item_admin( bp_user_has_access(), 'core' )'' is only
 neccessary for profiles, is it? If so, do we ever have profiles on a child
 site while BuddyPress is network wide activated?

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/4913>
BuddyPress <http://buddypress.org/>
BuddyPress


More information about the buddypress-trac mailing list