bp_friends_prefetch_activity_object_data( array $activities )

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

Description

This reduces database overhead during the activity loop.

Parameters

$activities

(Required) Array of activity items.

Return

(array)

Source

File: bp-friends/bp-friends-activity.php

function bp_friends_prefetch_activity_object_data( $activities ) {
	if ( empty( $activities ) ) {
		return $activities;
	}

	$friend_ids = array();

	foreach ( $activities as $activity ) {
		if ( buddypress()->friends->id !== $activity->component ) {
			continue;
		}

		$friend_ids[] = $activity->secondary_item_id;
	}

	if ( ! empty( $friend_ids ) ) {
		// Fire a user query to prime user caches.
		new BP_User_Query( array(
			'user_ids'          => $friend_ids,
			'populate_extras'   => false,
			'update_meta_cache' => false,
		) );
	}

	return $activities;
}

Changelog

Changelog
Version Description
BuddyPress 2.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.