Changeset 7771 for trunk/bp-activity/bp-activity-classes.php
- Timestamp:
- 02/03/2014 02:05:25 AM (13 years ago)
- File:
-
- 1 edited
-
trunk/bp-activity/bp-activity-classes.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r7765 r7771 138 138 global $wpdb, $bp; 139 139 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 ) ) { 141 147 $this->id = $row->id; 142 148 $this->item_id = $row->item_id; … … 477 483 $bp = buddypress(); 478 484 479 // Format the activity ID's for use in the query below 480 $activity_ids_sql = implode( ',', wp_parse_id_list( $activity_ids ) ); 481 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} )"); 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 } 518 519 // Reset indexes 520 $activities = array_values( $activities ); 484 521 485 522 // Then fetch user data
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)