Skip to:
Content

Opened 5 weeks ago

Last modified 5 days ago

#7513 accepted defect (bug)

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 5 weeks ago.
7513.2.diff (1.7 KB) - added by dcavins 5 weeks ago.
Respect that a dev can force-disable search by passing a search_term of .

Download all attachments as: .zip

Change History (8)

#1 @hnla
5 weeks ago

  • Keywords dev-feedback has-patch added

#2 @dcavins
5 weeks 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
5 weeks 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.


5 weeks ago

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


5 weeks ago

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


3 weeks ago

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


5 days ago

Note: See TracTickets for help on using tickets.