Skip to:
Content

BuddyPress.org

Ticket #7848: 7848.01.patch

File 7848.01.patch, 2.5 KB (added by r-a-y, 4 years ago)
  • src/bp-activity/classes/class-bp-activity-activity.php

     
    613613                        $from_sql   = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
    614614
    615615                        if ( ! empty( $page ) && ! empty( $per_page ) ) {
    616                                 $pag_sql    = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
     616                                $pag_sql = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
    617617
    618618                                /** This filter is documented in bp-activity/bp-activity-classes.php */
    619                                 $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}, a.id {$sort} {$pag_sql}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) );
     619                                $activity_sql = apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}, a.id {$sort} {$pag_sql}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql );
    620620                        } else {
    621                                 $pag_sql    = '';
     621                                $pag_sql = '';
    622622
    623623                                /**
    624624                                 * Filters the legacy MySQL query statement so plugins can alter before results are fetched.
     
    631631                                 * @param string $where_sql  Final WHERE MySQL statement portion for legacy query.
    632632                                 * @param string $sort       Final sort direction for legacy query.
    633633                                 */
    634                                 $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}, a.id {$sort}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) );
     634                                $activity_sql = apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}, a.id {$sort}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql );
    635635                        }
    636636
     637                        /*
     638                         * Queries that include 'last_activity' are cached separately,
     639                         * since they are generally much less long-lived.
     640                         */
     641                        if ( preg_match( '/a\.type NOT IN \([^\)]*\'last_activity\'[^\)]*\)/', $activity_sql ) ) {
     642                                $cache_group = 'bp_activity';
     643                        } else {
     644                                $cache_group = 'bp_activity_with_last_activity';
     645                        }
     646
     647                        $activities = $wpdb->get_results( $activity_sql );
     648
    637649                        // Integer casting for legacy activity query.
    638650                        foreach ( (array) $activities as $i => $ac ) {
    639651                                $activities[ $i ]->id                = (int) $ac->id;