[buddypress-trac] [BuddyPress] #4938: Logic for friend queries in BP_User_Query

buddypress-trac noreply at wordpress.org
Sun Apr 21 17:20:19 UTC 2013


#4938: Logic for friend queries in BP_User_Query
-------------------------+------------------
 Reporter:  dontdream    |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  1.8
Component:  Core         |     Version:  1.7
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------
Changes (by boonebgorges):

 * type:  defect (bug) => enhancement
 * milestone:  Awaiting Review => 1.8


Comment:

 Thanks for formatting as a patch, dontdream! Looks great.

 I think that the change you've suggested is a good one, but we should be
 clear on what it means. The attached patch (4938.patch) contains unit
 tests that demonstrate the two consequences of making your suggested
 change:

 - When you pass an 'include' parameter as well as 'user_id' parameter, you
 end up with two separate `WHERE ... IN` clauses. For example,
 `BP_User_Query( array( 'user_id' => 1, 'include' => array( 2,3) ) )` will
 result in a clause that looks like this (assuming that user 1's friends
 are 4 and 5): `u.user_id IN (4,5) AND u.user_id IN (2,3)`. Results will
 only be returned that match *all* of the clauses (it's an AND, not an OR).
 For the use case that you describe here, that's definitely what you want,
 and I think it will generally be the preferred behavior, but people who
 want to have inclusive SQL (where you return results that are EITHER
 friends of 1 OR in the array (2,3)) will have to use a different
 technique.

 - By extension, when a user has no friends, it doesn't matter what gets
 passed via 'include' - zero users should always be returned. For our
 situation, we're appending the 'no_results' clause `WHERE 0=1` in these
 cases (which speeds up the query, because SQL parses it first and skips
 the rest of the clauses).

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/4938#comment:5>
BuddyPress <http://buddypress.org/>
BuddyPress


More information about the buddypress-trac mailing list