bp_friends_prefetch_activity_object_data

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

Description

(array) bp_friends_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_friends_prefetch_activity_object_data' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-friends/bp-friends-activity.php'; 
  3.  
  4. // Array of activity items. 
  5. $activities = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_friends_prefetch_activity_object_data($activities); 
  9.  

Defined (1)

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

/bp-friends/bp-friends-activity.php  
  1. function bp_friends_prefetch_activity_object_data( $activities ) { 
  2. if ( empty( $activities ) ) { 
  3. return $activities; 
  4.  
  5. $friend_ids = array(); 
  6.  
  7. foreach ( $activities as $activity ) { 
  8. if (buddypress)->friends->id !== $activity->component ) { 
  9. continue; 
  10.  
  11. $friend_ids[] = $activity->secondary_item_id; 
  12.  
  13. if ( ! empty( $friend_ids ) ) { 
  14. // Fire a user query to prime user caches. 
  15. new BP_User_Query( array( 
  16. 'user_ids' => $friend_ids,  
  17. 'populate_extras' => false,  
  18. 'update_meta_cache' => false,  
  19. ) ); 
  20.  
  21. return $activities;