bp_blogs_prefetch_activity_object_data

Fetch data related to blogs at the beginning of an activity loop.

Description

(array) bp_blogs_prefetch_activity_object_data( (array) $activities ); 

This reduces database overhead during the activity loop.

Returns (array)

Parameters (1)

0. $activities (array)
Array of activity items.

Usage

  1. if ( !function_exists( 'bp_blogs_prefetch_activity_object_data' ) ) { 
  2. require_once '/bp-blogs/bp-blogs-activity.php'; 
  3.  
  4. // Array of activity items. 
  5. $activities = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_blogs_prefetch_activity_object_data($activities); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-blogs/bp-blogs-activity.php  
  1. function bp_blogs_prefetch_activity_object_data( $activities ) { 
  2. if ( empty( $activities ) ) { 
  3. return $activities; 
  4.  
  5. $blog_ids = array(); 
  6.  
  7. foreach ( $activities as $activity ) { 
  8. if ( buddypress()->blogs->id !== $activity->component ) { 
  9. continue; 
  10.  
  11. $blog_ids[] = $activity->item_id; 
  12.  
  13. if ( ! empty( $blog_ids ) ) { 
  14. bp_blogs_update_meta_cache( $blog_ids ); 
  15.  
  16. return $activities;