Skip to content

Commit

Permalink
PROD-7724 - Update query
Browse files Browse the repository at this point in the history
- Removed suspended users from follower and following count query
  • Loading branch information
jitendrabanjara1991 committed Oct 9, 2024
1 parent 9b0931b commit 25627ac
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions src/bp-activity/classes/class-bp-activity-follow.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,83 @@ public static function get_counts( $user_id ) {
$followers = wp_cache_get( 'bp_total_follower_for_user_' . $user_id, 'bp' );

if ( false === $followers ) {
$followers = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->activity->table_name_follow} WHERE leader_id = %d", $user_id ) );
/**
* Retrieves the count of users following a specific user.
*
* @since BuddyBoss [BBVERSION]
*
* @param int $user_id The user ID for whom the follower count is being retrieved.
*
* @return int The count of followers for the specified user.
*/
$sql['select'] = "SELECT COUNT(u.id) FROM {$bp->activity->table_name_follow} u";
/**
* Filters the SELECT clause for retrieving the follower count.
*
* @since BuddyBoss [BBVERSION]
*
* @param string $select The SELECT clause of the SQL query.
* @param string $type The type of data being queried, e.g., 'follower_id'.
*/
$sql['select'] = apply_filters( 'bp_user_query_join_sql', $sql['select'], 'follower_id' );

$sql['where'][] = $wpdb->prepare( "u.leader_id = %d", $user_id );
/**
* Filters the WHERE clause for retrieving the follower count.
*
* @since BuddyBoss [BBVERSION]
*
* @param array $where Array of WHERE clause conditions.
* @param string $type The type of data being queried, e.g., 'follower_id'.
*/
$sql['where'] = apply_filters( 'bp_user_query_where_sql', $sql['where'], 'follower_id' );

$where_sql = 'WHERE ' . join( ' AND ', $sql['where'] );

$sql = "{$sql['select']} {$where_sql}";
$followers = $wpdb->get_var( $sql );
wp_cache_set( 'bp_total_follower_for_user_' . $user_id, $followers, 'bp' );
}

$following = wp_cache_get( 'bp_total_following_for_user_' . $user_id, 'bp' );

if ( false === $following ) {
$following = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->activity->table_name_follow} WHERE follower_id = %d", $user_id ) );
$sql = array();
/**
* Retrieves the count of users being followed by a specific user.
*
* @since BuddyBoss [BBVERSION]
*
* @param int $user_id The user ID for whom the follow count is being retrieved.
*
* @return int The count of users the specified user is following.
*/
$sql['select'] = "SELECT COUNT(u.id) FROM {$bp->activity->table_name_follow} u";
/**
* Filters the SELECT clause for retrieving the follow count.
*
* @since BuddyBoss [BBVERSION]
*
* @param string $select The SELECT clause of the SQL query.
* @param string $type The type of data being queried, e.g., 'leader_id'.
*/
$sql['select'] = apply_filters( 'bp_user_query_join_sql', $sql['select'], 'leader_id' );

$sql['where'][] = $wpdb->prepare( "u.follower_id = %d", $user_id );
/**
* Filters the WHERE clause for retrieving the follow count.
*
* @since BuddyBoss [BBVERSION]
*
* @param array $where Array of WHERE clause conditions.
* @param string $type The type of data being queried, e.g., 'leader_id'.
*/
$sql['where'] = apply_filters( 'bp_user_query_where_sql', $sql['where'], 'leader_id' );

$where_sql = 'WHERE ' . join( ' AND ', $sql['where'] );

$sql = "{$sql['select']} {$where_sql}";
$following = $wpdb->get_var( $sql );
wp_cache_set( 'bp_total_following_for_user_' . $user_id, $following, 'bp' );
}

Expand Down

0 comments on commit 25627ac

Please sign in to comment.