Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/20/2014 03:16:52 PM (10 years ago)
Author:
boonebgorges
Message:

Don't query for group extras if user is not logged in

Saves a couple needless database queries for unauthenticated users.

Fixes #5416

Props lenasterg for initial patch

File:
1 edited

Legend:

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

    r7934 r7939  
    12231223
    12241224        // Fetch the logged-in user's status within each group
    1225         $user_status_results = $wpdb->get_results( $wpdb->prepare( "SELECT group_id, is_confirmed, invite_sent FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_banned = 0", bp_loggedin_user_id() ) );
     1225        if ( is_user_logged_in() ) {
     1226            $user_status_results = $wpdb->get_results( $wpdb->prepare( "SELECT group_id, is_confirmed, invite_sent FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_banned = 0", bp_loggedin_user_id() ) );
     1227        } else {
     1228            $user_status_results = array();
     1229        }
    12261230
    12271231        // Reindex
     
    12561260        }
    12571261
    1258         $user_banned = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE is_banned = 1 AND user_id = %d AND group_id IN ( {$group_ids} )", bp_loggedin_user_id() ) );
     1262        if ( is_user_logged_in() ) {
     1263            $user_banned = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE is_banned = 1 AND user_id = %d AND group_id IN ( {$group_ids} )", bp_loggedin_user_id() ) );
     1264        } else {
     1265            $user_banned = array();
     1266        }
     1267
    12591268        for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) {
    12601269            $paged_groups[$i]->is_banned = false;
Note: See TracChangeset for help on using the changeset viewer.