Skip to content

Commit

Permalink
WIP - group member query
Browse files Browse the repository at this point in the history
  • Loading branch information
KartikSuthar committed Jan 23, 2025
1 parent f2cd17d commit d19002b
Show file tree
Hide file tree
Showing 7 changed files with 483 additions and 273 deletions.
2 changes: 1 addition & 1 deletion src/bp-core/classes/class-bp-invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ public static function get( $args = array() ) {
$paged_invites_sql = apply_filters( 'bp_invitations_get_paged_invitations_sql', $paged_invites_sql, $sql, $r );

if ( ! empty( $r['retval'] ) && 'sql' == $r['retval'] ) {
return str_replace( $sql['orderby'] . ' ' . $sql['pagination'], '', $paged_invites_sql );
return $sql;
}

$cached = bp_core_get_incremented_cache( $paged_invites_sql, 'bp_invitations' );
Expand Down
20 changes: 3 additions & 17 deletions src/bp-core/classes/class-bp-user-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,7 @@ public function prepare_user_ids_query() {

// 'include' - User ids to include in the results.
$include = false !== $include ? wp_parse_id_list( $include ) : array();

$include_ids_sql = $this->get_include_ids_sql( $include );
$include_ids = array();
if ( empty( $include_ids_sql ) ) {
$include_ids = $this->get_include_ids( $include );
}
$include_ids = $this->get_include_ids( $include );

/* TYPE **************************************************************/

Expand Down Expand Up @@ -387,10 +382,7 @@ public function prepare_user_ids_query() {
$this->uid_name = 'ID';
$this->uid_table = $wpdb->users;
$sql['select'] = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
if ( ! empty( $include_ids_sql ) ) {
$sql['where'][] = "u.{$this->uid_name} IN ({$include_ids_sql})";
$sql['orderby'] = "ORDER BY FIELD(u.{$this->uid_name}, {$include_ids_sql})";
} else if ( ! empty( $include_ids ) ) {
if ( ! empty( $include_ids ) ) {
$include_ids = implode( ',', wp_parse_id_list( $include_ids ) );
$sql['where'][] = "u.{$this->uid_name} IN ({$include_ids})";
$sql['orderby'] = "ORDER BY FIELD(u.{$this->uid_name}, {$include_ids})";
Expand Down Expand Up @@ -422,9 +414,7 @@ public function prepare_user_ids_query() {
/* WHERE *************************************************************/

// An array containing nothing but 0 should always fail.
if ( ! empty( $include_ids_sql ) ) {
$sql['where'][] = "u.{$this->uid_name} IN ({$include_ids_sql})";
} else if ( is_array( $include_ids ) && 1 === count( $include_ids ) && 0 == reset( $include_ids ) ) {
if ( is_array( $include_ids ) && 1 === count( $include_ids ) && 0 == reset( $include_ids ) ) {
$sql['where'][] = $this->no_results['where'];
} elseif ( ! empty( $include_ids ) ) {
$include_ids = implode( ',', wp_parse_id_list( $include_ids ) );
Expand Down Expand Up @@ -727,10 +717,6 @@ public function get_include_ids( $include = array() ) {
return $include;
}

public function get_include_ids_sql( $include = array() ) {
return '';
}

/**
* Perform a database query to populate any extra metadata we might need.
*
Expand Down
2 changes: 1 addition & 1 deletion src/bp-groups/bp-groups-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ function groups_get_group_members( $args = array() ) {
$cache_key = 'bp_groups_get_group_members_' . md5( maybe_serialize( $group_member_args ) );
if ( ! isset( $cache[ $cache_key ] ) ) {
// Perform the group member query (extends BP_User_Query).
$members = new BP_Group_Member_Query( $group_member_args );
$members = new BB_Group_Member_Query( $group_member_args );

$cache[ $cache_key ] = $members;
} else {
Expand Down
Loading

0 comments on commit d19002b

Please sign in to comment.