Skip to:
Content

BuddyPress.org

Changeset 7966


Ignore:
Timestamp:
02/22/2014 09:21:21 PM (10 years ago)
Author:
r-a-y
Message:

Don't fetch item counts in profile navigation unnecessarily.

Previously, when a component's setup_nav() method is fired, the item
count for the component is fetched without any conditional checks.

This causes unneccessary queries to be fired when a user isn't logged
in or when we're not on a single user page.

This commit only fetches the item count in the profile nav if we're
currently on a single user page and/or if the current user has access
to the component nav item.

Fixes #5413

Props r-a-y, boonebgorges

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-loader.php

    r7840 r7966  
    347347    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    348348
     349        // Only grab count if we're on a user page
     350        if ( bp_is_user() ) {
     351            $count    = bp_get_total_group_count_for_user();
     352            $class    = ( 0 === $count ) ? 'no-count' : 'count';
     353            $nav_name = sprintf( __( 'Groups <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) );
     354        } else {
     355            $nav_name = __( 'Groups', 'buddypress' );
     356        }
     357
    349358        // Add 'Groups' to the main navigation
    350         $count    = bp_get_total_group_count_for_user();
    351         $class    = ( 0 === $count ) ? 'no-count' : 'count';
    352359        $main_nav = array(
    353             'name'                => sprintf( __( 'Groups <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) ),
     360            'name'                => $nav_name,
    354361            'slug'                => $this->slug,
    355362            'position'            => 70,
  • trunk/bp-messages/bp-messages-loader.php

    r7758 r7966  
    103103    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    104104
     105        // Only grab count if we're on a user page and current user has access
     106        if ( bp_is_user() && bp_user_has_access() ) {
     107            $count    = bp_get_total_unread_messages_count();
     108            $class    = ( 0 === $count ) ? 'no-count' : 'count';
     109            $nav_name = sprintf( __( 'Messages <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) );
     110        } else {
     111            $nav_name = __( 'Messages', 'buddypress' );
     112        }
     113
    105114        // Add 'Messages' to the main navigation
    106         $count    = bp_get_total_unread_messages_count();
    107         $class    = ( 0 === $count ) ? 'no-count' : 'count';
    108115        $main_nav = array(
    109             'name'                    => sprintf( __( 'Messages <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) ),
     116            'name'                    => $nav_name,
    110117            'slug'                    => $this->slug,
    111118            'position'                => 50,
  • trunk/bp-notifications/bp-notifications-loader.php

    r7936 r7966  
    105105    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    106106
     107        // Only grab count if we're on a user page and current user has access
     108        if ( bp_is_user() && bp_user_has_access() ) {
     109            $count    = bp_notifications_get_unread_notification_count( bp_displayed_user_id() );
     110            $class    = ( 0 === $count ) ? 'no-count' : 'count';
     111            $nav_name = sprintf( __( 'Notifications <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) );
     112        } else {
     113            $nav_name = __( 'Notifications', 'buddypress' );
     114        }
     115
    107116        // Add 'Notifications' to the main navigation
    108         $count    = bp_notifications_get_unread_notification_count( bp_displayed_user_id() );
    109         $class    = ( 0 === $count ) ? 'no-count' : 'count';
    110117        $main_nav = array(
    111             'name'                    => sprintf( __( 'Notifications <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) ),
     118            'name'                    => $nav_name,
    112119            'slug'                    => $this->slug,
    113120            'position'                => 30,
Note: See TracChangeset for help on using the changeset viewer.