Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/11/2015 06:53:59 AM (11 years ago)
Author:
johnjamesjacoby
Message:

Loaders: Micro-optimizations:

  • Add brackets for improved readability
  • Only instantiate $bp from buddypress() when used more than once, and after all early return conditions have executed
  • Use _slug_ functions where appropriate, and avoid $this->slug references as they do not run filters
  • Reduce mulitple calls to the same functions into 1 function call: I.E. bp_core_can_edit_settings()
  • Remove BP_Core_Component::setup_nav() method - it's been handled and duplicated by BP_Members_Component for several years now, and only when XProfile is disabled
  • Use new bp_get_profile_slug() functions where appropriate
  • Use bp_core_number_format() where appropriate
  • Avoid duplicate trailingslashit() calls on the same variables
  • Rely on canonical menu URLs for all components

This change touches each component's -loader.php file and makes several small optimizations that avoid executing hundreds of function calls that return data (specifically gettext) that never gets used on logged-out users. This results in an approximate 20% reduction in time spent running our full unit test suite in my testing, and also improves site performance for logged-out users.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-loader.php

    r9877 r9936  
    142142                /** Profiles Fallback *************************************************/
    143143
    144                 if ( !bp_is_active( 'xprofile' ) ) {
     144                if ( ! bp_is_active( 'xprofile' ) ) {
    145145                        $bp->profile       = new stdClass;
    146146                        $bp->profile->slug = 'profile';
     
    231231                }
    232232
    233                 $bp = buddypress();
     233                // Determine user to use
     234                if ( bp_displayed_user_domain() ) {
     235                        $user_domain = bp_displayed_user_domain();
     236                } elseif ( bp_loggedin_user_domain() ) {
     237                        $user_domain = bp_loggedin_user_domain();
     238                } else {
     239                        return;
     240                }
     241
     242                $slug         = bp_get_profile_slug();
     243                $profile_link = trailingslashit( $user_domain . $slug );
    234244
    235245                // Setup the main navigation
    236246                $main_nav = array(
    237247                        'name'                => _x( 'Profile', 'Member profile main navigation', 'buddypress' ),
    238                         'slug'                => $bp->profile->slug,
     248                        'slug'                => $slug,
    239249                        'position'            => 20,
    240250                        'screen_function'     => 'bp_members_screen_display_profile',
    241251                        'default_subnav_slug' => 'public',
    242                         'item_css_id'         => $bp->profile->id
    243                 );
    244 
    245                 // User links
    246                 $user_domain  = bp_displayed_user_domain() ? bp_displayed_user_domain() : bp_loggedin_user_domain();
    247                 $profile_link = trailingslashit( $user_domain . $bp->profile->slug );
     252                        'item_css_id'         => buddypress()->profile->id
     253                );
    248254
    249255                // Setup the subnav items for the member profile
     
    252258                        'slug'            => 'public',
    253259                        'parent_url'      => $profile_link,
    254                         'parent_slug'     => $bp->profile->slug,
     260                        'parent_slug'     => $slug,
    255261                        'screen_function' => 'bp_members_screen_display_profile',
    256262                        'position'        => 10
Note: See TracChangeset for help on using the changeset viewer.