Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/11/2015 06:53:59 AM (9 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-xprofile/bp-xprofile-loader.php

    r9819 r9936  
    172172    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    173173
    174         $sub_nav = array();
     174        // Determine user to use
     175        if ( bp_displayed_user_domain() ) {
     176            $user_domain = bp_displayed_user_domain();
     177        } elseif ( bp_loggedin_user_domain() ) {
     178            $user_domain = bp_loggedin_user_domain();
     179        } else {
     180            return;
     181        }
     182
     183        $slug         =
     184        $profile_link = trailingslashit( $user_domain . $this->slug );
    175185
    176186        // Add 'Profile' to the main navigation
     
    183193            'item_css_id'         => $this->id
    184194        );
    185 
    186         // Determine user to use
    187         if ( bp_displayed_user_domain() ) {
    188             $user_domain = bp_displayed_user_domain();
    189         } elseif ( bp_loggedin_user_domain() ) {
    190             $user_domain = bp_loggedin_user_domain();
    191         } else {
    192             return;
    193         }
    194 
    195         $profile_link = trailingslashit( $user_domain . $this->slug );
    196195
    197196        // Add the subnav items to the profile
     
    276275     */
    277276    public function setup_admin_bar( $wp_admin_nav = array() ) {
    278         $bp = buddypress();
    279 
    280         // Prevent debug notices
    281         $wp_admin_nav = array();
    282277
    283278        // Menus for logged in user
     
    285280
    286281            // Profile link
    287             $profile_link = trailingslashit( bp_loggedin_user_domain() . $this->slug );
     282            $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() );
    288283
    289284            // Add the "Profile" sub menu
    290285            $wp_admin_nav[] = array(
    291                 'parent' => $bp->my_account_menu_id,
     286                'parent' => buddypress()->my_account_menu_id,
    292287                'id'     => 'my-account-' . $this->id,
    293288                'title'  => _x( 'Profile', 'My Account Profile', 'buddypress' ),
    294                 'href'   => trailingslashit( $profile_link )
     289                'href'   => $profile_link
    295290            );
    296291
     
    300295                'id'     => 'my-account-' . $this->id . '-public',
    301296                'title'  => _x( 'View', 'My Account Profile sub nav', 'buddypress' ),
    302                 'href'   => trailingslashit( $profile_link . 'public' )
     297                'href'   => $profile_link
    303298            );
    304299
     
    339334     */
    340335    public function setup_title() {
    341         $bp = buddypress();
    342336
    343337        if ( bp_is_profile_component() ) {
     338            $bp = buddypress();
     339
    344340            if ( bp_is_my_profile() ) {
    345341                $bp->bp_options_title = _x( 'My Profile', 'Page title', 'buddypress' );
     
    384380     */
    385381    public function setup_settings_admin_nav( $wp_admin_nav ) {
     382
    386383        // Setup the logged in user variables
    387384        $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() );
Note: See TracChangeset for help on using the changeset viewer.