Skip to:
Content

Ticket #5350: 5350.patch

File 5350.patch, 3.5 KB (added by boonebgorges, 4 years ago)
  • bp-activity/bp-activity-cache.php

    diff --git bp-activity/bp-activity-cache.php bp-activity/bp-activity-cache.php
    index 1fbd80b..eff3624 100644
    function bp_activity_clear_meta_cache_for_activity( $activity_id ) { 
    5353                } 
    5454        } 
    5555} 
     56 
     57/** 
     58 * Clear a cached activity item when that item is updated. 
     59 * 
     60 * @since 2.0 
     61 * 
     62 * @param BP_Activity_Activity $activity 
     63 */ 
     64function bp_activity_clear_cache_for_activity( $activity ) { 
     65        wp_cache_delete( 'activity_' . $activity->id, 'bp' ); 
     66} 
     67add_action( 'bp_activity_after_save', 'bp_activity_clear_cache_for_activity' ); 
     68 
     69/** 
     70 * Clear cached data for deleted activity items. 
     71 * 
     72 * @since 2.0 
     73 * 
     74 * @param array $deleted_ids IDs of deleted activity items. 
     75 */ 
     76function bp_activity_clear_cache_for_deleted_activity( $deleted_ids ) { 
     77        foreach ( (array) $deleted_ids as $deleted_id ) { 
     78                wp_cache_delete( 'activity_' . $deleted_id, 'bp' ); 
     79        } 
     80} 
     81add_action( 'bp_activity_deleted_activities', 'bp_activity_clear_cache_for_deleted_activity' ); 
  • bp-activity/bp-activity-classes.php

    diff --git bp-activity/bp-activity-classes.php bp-activity/bp-activity-classes.php
    index 016c8dd..3131493 100644
    class BP_Activity_Activity { 
    137137        public function populate() { 
    138138                global $wpdb, $bp; 
    139139 
    140                 if ( $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) ) ) { 
     140                $row = wp_cache_get( 'activity_' . $this->id, 'bp' ); 
     141 
     142                if ( false === $row ) { 
     143                        $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) ); 
     144                } 
     145 
     146                if ( ! empty( $row ) ) { 
    141147                        $this->id                = $row->id; 
    142148                        $this->item_id           = $row->item_id; 
    143149                        $this->secondary_item_id = $row->secondary_item_id; 
    class BP_Activity_Activity { 
    476482                // Get BuddyPress 
    477483                $bp = buddypress(); 
    478484 
    479                 // Format the activity ID's for use in the query below 
    480                 $activity_ids_sql = implode( ',', wp_parse_id_list( $activity_ids ) ); 
     485                $activities = array(); 
     486                $query_aids = array(); 
     487 
     488                foreach ( $activity_ids as $activity_id ) { 
     489 
     490                        // If cached data is found, use it 
     491                        if ( $activity_data = wp_cache_get( 'activity_' . $activity_id, 'bp' ) ) { 
     492                                $activities[ $activity_id ] = $activity_data; 
     493 
     494                        // Otherwise leave a placeholder so we don't lose the order 
     495                        } else { 
     496                                $activities[ $activity_id ] = ''; 
     497 
     498                                // Add to the list to be queried 
     499                                $query_aids[] = $activity_id; 
     500                        } 
     501                } 
     502 
     503                // Fetch activity data from the DB if necessary 
     504                if ( ! empty( $query_aids ) ) { 
     505                        // Format the activity ID's for use in the query below 
     506                        $query_aids_sql = implode( ',', wp_parse_id_list( $query_aids ) ); 
     507 
     508                        // Fetch data from activity table, preserving order 
     509                        $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$query_aids_sql}) ORDER BY FIELD( id, {$query_aids_sql} )"); 
     510 
     511                        // Put that data into the placeholders created earlier, 
     512                        // and add it to the cache 
     513                        foreach ( (array) $queried_adata as $adata ) { 
     514                                $activities[ $adata->id ] = $adata; 
     515                                wp_cache_set( 'activity_' . $adata->id, $adata, 'bp' ); 
     516                        } 
     517                } 
    481518 
    482                 // First fetch data from activity table, preserving order 
    483                 $activities = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids_sql}) ORDER BY FIELD( id, {$activity_ids_sql} )"); 
     519                // Reset indexes 
     520                $activities = array_values( $activities ); 
    484521 
    485522                // Then fetch user data 
    486523                $user_query = new BP_User_Query( array(