Skip to:
Content

BuddyPress.org

Changeset 7777


Ignore:
Timestamp:
02/04/2014 01:16:37 AM (7 years ago)
Author:
boonebgorges
Message:

Split activity comments query into searate ID query

This eliminates joins against the global user table, and also centralizes
caching for individual activity items.

Fixes #5371

File:
1 edited

Legend:

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

    r7776 r7777  
    918918            }
    919919
    920             // The mptt BETWEEN clause allows us to limit returned descendants to the right part of the tree
    921             $sql = apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' {$spam_sql} AND a.item_id = %d AND a.mptt_left > %d AND a.mptt_left < %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right ), $activity_id, $left, $right, $spam_sql );
    922 
    923             // Retrieve all descendants of the $root node
    924             $descendants = $wpdb->get_results( $sql );
    925             $ref         = array();
     920            // Legacy query - not recommended
     921            if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, func_get_args() ) ) {
     922                $sql = apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' {$spam_sql} AND a.item_id = %d AND a.mptt_left > %d AND a.mptt_left < %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right ), $activity_id, $left, $right, $spam_sql );
     923
     924                $descendants = $wpdb->get_results( $sql );
     925
     926            // We use the mptt BETWEEN clause to limit returned
     927            // descendants to the correct part of the tree.
     928            } else {
     929                $sql = $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} a WHERE a.type = 'activity_comment' {$spam_sql} AND a.item_id = %d and a.mptt_left > %d AND a.mptt_left < %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right );
     930
     931                $descendant_ids = $wpdb->get_col( $sql );
     932                $descendants    = self::get_activity_data( $descendant_ids );
     933                $descendands    = self::append_user_fullnames( $descendants );
     934            }
     935
     936            $ref = array();
    926937
    927938            // Loop descendants and build an assoc array
Note: See TracChangeset for help on using the changeset viewer.