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-core/bp-core-loader.php

    r9819 r9936  
    151151        public function includes( $includes = array() ) {
    152152
    153                 if ( !is_admin() )
     153                if ( ! is_admin() ) {
    154154                        return;
     155                }
    155156
    156157                $includes = array(
     
    179180
    180181                // Get the base database prefix
    181                 if ( empty( $bp->table_prefix ) )
     182                if ( empty( $bp->table_prefix ) ) {
    182183                        $bp->table_prefix = bp_core_get_table_prefix();
     184                }
    183185
    184186                // The domain for the root of the site where the main blog resides
    185                 if ( empty( $bp->root_domain ) )
     187                if ( empty( $bp->root_domain ) ) {
    186188                        $bp->root_domain = bp_core_get_root_domain();
     189                }
    187190
    188191                // Fetches all of the core BuddyPress settings in one fell swoop
    189                 if ( empty( $bp->site_options ) )
     192                if ( empty( $bp->site_options ) ) {
    190193                        $bp->site_options = bp_core_get_root_options();
     194                }
    191195
    192196                // The names of the core WordPress pages used to display BuddyPress content
    193                 if ( empty( $bp->pages ) )
     197                if ( empty( $bp->pages ) ) {
    194198                        $bp->pages = bp_core_get_directory_pages();
     199                }
    195200
    196201                /** Basic current user data *******************************************/
     
    261266
    262267        /**
    263          * Set up component navigation.
    264          *
    265          * @since BuddyPress (1.5.0)
    266          *
    267          * @see BP_Component::setup_nav() for a description of arguments.
    268          *
    269          * @param array $main_nav Optional. See BP_Component::setup_nav() for
    270          *        description.
    271          * @param array $sub_nav Optional. See BP_Component::setup_nav() for
    272          *        description.
    273          */
    274         public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    275                 $bp = buddypress();
    276 
    277                  // If xprofile component is disabled, revert to WordPress profile
    278                 if ( !bp_is_active( 'xprofile' ) ) {
    279 
    280                         // Fallback values if xprofile is disabled
    281                         if ( ! isset( $bp->core->profile ) ) {
    282                                 $bp->core->profile = new stdClass;
    283                         }
    284                         $bp->core->profile->slug = 'profile';
    285                         $bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
    286 
    287                         // Add 'Profile' to the main navigation
    288                         $main_nav = array(
    289                                 'name'                => _x( 'Profile', 'Main navigation', 'buddypress' ),
    290                                 'slug'                => $bp->core->profile->slug,
    291                                 'position'            => 20,
    292                                 'screen_function'     => 'bp_core_catch_profile_uri',
    293                                 'default_subnav_slug' => 'public'
    294                         );
    295 
    296                         $profile_link = trailingslashit( bp_loggedin_user_domain() . '/' . $bp->core->profile->slug );
    297 
    298                         // Add the subnav items to the profile
    299                         $sub_nav[] = array(
    300                                 'name'            => _x( 'View', 'Profile sub nav', 'buddypress' ),
    301                                 'slug'            => 'public',
    302                                 'parent_url'      => $profile_link,
    303                                 'parent_slug'     => $bp->core->profile->slug,
    304                                 'screen_function' => 'bp_core_catch_profile_uri'
    305                         );
    306 
    307                         parent::setup_nav( $main_nav, $sub_nav );
    308                 }
    309         }
    310 
    311         /**
    312268         * Setup cache groups
    313269         *
Note: See TracChangeset for help on using the changeset viewer.