Opened 11 years ago
Closed 11 years ago
#5413 closed defect (bug) (fixed)
Don't query for item counts in profile nav when not needed
Reported by: | r-a-y | Owned by: | r-a-y |
---|---|---|---|
Milestone: | 2.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Core | Keywords: | has-patch |
Cc: |
Description
When a component's setup_nav()
method is fired, we currently do no checks for when an item count is fired.
This causes unnecessary queries to be fired when a user isn't logged in or when not on an appropriate BP page.
Attached is a quick patch before I forget to add one!
The only caveat with the patch is if a dev is manually calling the profile nav somewhere else that is not a profile page.
Attachments (1)
Change History (5)
#2
@
11 years ago
Good idea.
The only caveat with the patch is if a dev is manually calling the profile nav somewhere else that is not a profile page.
I don't think we really support this anyway - our nav is riddled with calls to bp_displayed_user_id(). That said, one way to work around it would be to skip adding the counts in those cases:
if ( bp_is_user() ) { $count = bp_get_total_group_count_for_user(); $class = ( 0 === $count ) ? 'no-count' : 'count'; $nav_name = sprintf( __( 'Groups <span class=%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) ); } else { $nav_name = __( 'Groups', 'buddypress' ); }
Then, at least, we won't be outputting zeros where a zero would be technically incorrect.
Nice!!!