Skip to:
Content

Opened 3 months ago

Closed 5 weeks ago

#7513 closed defect (bug) (fixed)

bp_group_has_members performs unnecessary query

Reported by: brandonliles Owned by: dcavins
Milestone: 2.9 Priority: normal
Severity: normal Version: 1.0
Component: Groups Keywords: dev-feedback has-patch 2nd-opinion
Cc:

Description

The function bp_group_has_members defaults the query parameter 'search_terms' to null when there are no search terms, but BP_User_Query expects that 'search_terms' is false rather than null. This results in BP_User_Query issuing an unnecessary table scan on the users table.

Attachments (2)

buddypress-search-terms-bug.patch (810 bytes) - added by brandonliles 3 months ago.
7513.2.diff (1.7 KB) - added by dcavins 3 months ago.
Respect that a dev can force-disable search by passing a search_term of .

Download all attachments as: .zip

Change History (9)

#1 @hnla
3 months ago

  • Keywords dev-feedback has-patch added

#2 @dcavins
3 months ago

  • Component changed from Core to Groups
  • Keywords 2nd-opinion added
  • Milestone changed from Awaiting Review to 2.9
  • Owner set to dcavins
  • Status changed from new to accepted
  • Version set to 1.0

Hi @brandonliles-

Thanks for finding this inefficiency! In reading the documentation for the function, it looks like fixing it is slightly more complicated than first thought.

$search_terms - Optional. Search terms to match. Pass an empty string to force-disable search, even in the presence of $_REQUEST[s].

The key part of your patch is that search_terms => false is passed to BP_Groups_Group_Members_Template so that ultimately BP_User_Query stops doing

WHERE ( user_login LIKE '%%'
OR user_login LIKE '%%'
OR user_nicename LIKE '%%'
OR user_nicename LIKE '%%' ) ) )

all the time. I've added some logic to make sure that our documentation is observed while keeping the core of your patch.

Great find!

-David

@dcavins
3 months ago

Respect that a dev can force-disable search by passing a search_term of .

This ticket was mentioned in Slack in #buddypress by dcavins. View the logs.


3 months ago

This ticket was mentioned in Slack in #buddypress by hnla. View the logs.


3 months ago

This ticket was mentioned in Slack in #buddypress by hnla. View the logs.


3 months ago

This ticket was mentioned in Slack in #buddypress by dcavins. View the logs.


2 months ago

#7 @dcavins
5 weeks ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 11595:

Correct search_term parameter in bp_group_has_members().

The function bp_group_has_members() defaults the query parameter
search_terms to null when there are no search terms, but
BP_User_Query expects search_terms to be false rather than null
when a search is not needed.

Props brandonliles.

Fixes #7513.

Note: See TracTickets for help on using tickets.