bp_friends_prefetch_activity_object_data( array $activities )

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


Description Description

This reduces database overhead during the activity loop.


Top ↑

Parameters Parameters

$activities

(array) (Required) Array of activity items.


Top ↑

Return Return

(array)


Source 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;
}


Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.