Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/11/2015 06:53:59 AM (10 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-screens.php

    r9819 r9936  
    5353function xprofile_screen_edit_profile() {
    5454
    55     if ( !bp_is_my_profile() && !bp_current_user_can( 'bp_moderate' ) )
     55    if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
    5656        return false;
    57 
    58     $bp = buddypress();
     57    }
    5958
    6059    // Make sure a group is set.
    61     if ( !bp_action_variable( 1 ) )
    62         bp_core_redirect( trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/1' ) );
     60    if ( ! bp_action_variable( 1 ) ) {
     61        bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/1' ) );
     62    }
    6363
    6464    // Check the field group exists
    65     if ( !bp_is_action_variable( 'group' ) || !xprofile_get_field_group( bp_action_variable( 1 ) ) ) {
     65    if ( ! bp_is_action_variable( 'group' ) || ! xprofile_get_field_group( bp_action_variable( 1 ) ) ) {
    6666        bp_do_404();
    6767        return;
     
    7878
    7979        // Check we have field ID's
    80         if ( empty( $_POST['field_ids'] ) )
    81             bp_core_redirect( trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable( 1 ) ) );
     80        if ( empty( $_POST['field_ids'] ) ) {
     81            bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . bp_action_variable( 1 ) ) );
     82        }
    8283
    8384        // Explode the posted field IDs into an array so we know which
     
    181182
    182183            // Redirect back to the edit screen to display the updates and message
    183             bp_core_redirect( trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable( 1 ) ) );
     184            bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . bp_action_variable( 1 ) ) );
    184185        }
    185186    }
     
    212213
    213214    // Bail if not the correct screen
    214     if ( !bp_is_my_profile() && !bp_current_user_can( 'bp_moderate' ) )
     215    if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
    215216        return false;
     217    }
    216218
    217219    // Bail if there are action variables
     
    223225    $bp = buddypress();
    224226
    225     if ( ! isset( $bp->avatar_admin ) )
     227    if ( ! isset( $bp->avatar_admin ) ) {
    226228        $bp->avatar_admin = new stdClass();
     229    }
    227230
    228231    $bp->avatar_admin->step = 'upload-image';
Note: See TracChangeset for help on using the changeset viewer.