Changeset 8075
- Timestamp:
- 03/07/2014 01:32:01 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r8071 r8075 471 471 $bp = buddypress(); 472 472 473 $activities = array(); 474 $query_aids = array(); 475 476 foreach ( $activity_ids as $activity_id ) { 477 478 // If cached data is found, use it 479 if ( $activity_data = wp_cache_get( $activity_id, 'bp_activity' ) ) { 480 $activities[ $activity_id ] = $activity_data; 481 482 // Otherwise leave a placeholder so we don't lose the order 483 } else { 484 $activities[ $activity_id ] = ''; 485 486 // Add to the list to be queried 487 $query_aids[] = $activity_id; 488 } 489 } 490 491 // Fetch activity data from the DB if necessary 492 if ( ! empty( $query_aids ) ) { 473 $activities = array(); 474 $uncached_ids = bp_get_non_cached_ids( $activity_ids, 'bp_activity' ); 475 476 // Prime caches as necessary 477 if ( ! empty( $uncached_ids ) ) { 493 478 // Format the activity ID's for use in the query below 494 $ query_aids_sql = implode( ',', wp_parse_id_list( $query_aids ) );479 $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) ); 495 480 496 481 // Fetch data from activity table, preserving order 497 $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$ query_aids_sql}) ORDER BY FIELD( id, {$query_aids_sql})");482 $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$uncached_ids_sql})"); 498 483 499 484 // Put that data into the placeholders created earlier, 500 485 // and add it to the cache 501 486 foreach ( (array) $queried_adata as $adata ) { 502 $activities[ $adata->id ] = $adata;503 487 wp_cache_set( $adata->id, $adata, 'bp_activity' ); 504 488 } 505 489 } 506 490 507 // Reset indexes 508 $activities = array_values( $activities ); 491 // Now fetch data from the cache 492 foreach ( $activity_ids as $activity_id ) { 493 $activities[] = wp_cache_get( $activity_id, 'bp_activity' ); 494 } 509 495 510 496 // Then fetch user data
Note: See TracChangeset
for help on using the changeset viewer.