diff --git bp-activity/bp-activity-classes.php bp-activity/bp-activity-classes.php
index c510b77..c9aee76 100644
|
|
class BP_Activity_Activity { |
106 | 106 | // Select conditions |
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 |
112 | 112 | $where_conditions = array(); |
… |
… |
class BP_Activity_Activity { |
155 | 155 | |
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 | |
160 | 176 | // Make sure page values are absolute integers |
… |
… |
class BP_Activity_Activity { |
167 | 183 | $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $select_sql, $from_sql, $where_sql, $sort ) ); |
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 ); |
173 | 189 | |