Changeset 5940
- Timestamp:
- 03/20/2012 09:16:58 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r5926 r5940 107 107 $select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name"; 108 108 109 $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";109 $from_sql = " FROM {$bp->activity->table_name} a USE INDEX (date_recorded) LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID"; 110 110 111 111 // Where conditions … … 156 156 $where_sql = 'WHERE ' . join( ' AND ', $where_conditions ); 157 157 158 // Define the preferred order for indexes 159 $indexes = apply_filters( 'bp_activity_preferred_index_order', array( 'user_id', 'item_id', 'secondary_item_id', 'date_recorded', 'component', 'type', 'hide_sitewide', 'is_spam' ) ); 160 161 foreach( $indexes as $key => $index ) { 162 if ( false !== strpos( $where_sql, $index ) ) { 163 $the_index = $index; 164 break; // Take the first one we find 165 } 166 } 167 168 if ( !empty( $the_index ) ) { 169 $index_hint_sql = $wpdb->prepare( "USE INDEX ({$the_index})" ); 170 } else { 171 $index_hint_sql = ''; 172 } 173 158 174 if ( !empty( $per_page ) && !empty( $page ) ) { 159 175 … … 168 184 } 169 185 170 $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$ where_sql} ORDER BY a.date_recorded {$sort}" ), $where_sql, $sort );186 $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$index_hint_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $where_sql, $sort ); 171 187 172 188 $total_activities = $wpdb->get_var( $total_activities_sql );
Note: See TracChangeset
for help on using the changeset viewer.