Skip to:
Content

BuddyPress.org

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#5118 closed defect (bug) (fixed)

Activities meta_query can load duplicates

Reported by: imath's profile imath Owned by: boonebgorges's profile boonebgorges
Milestone: 1.8.1 Priority: high
Severity: normal Version: 1.8
Component: Activity Keywords:
Cc:

Description

Let's say i have this meta_query :

$meta_query = array(
	'relation' => 'OR',
	array(
		'key' => 'test',
		'value' => 1,
		'type' => 'numeric',
		'compare' => '='
	), 
	array(
		'key' => 'rand',
		'value' => 2,
		'type' => 'numeric',
		'compare' => '='
	)
);

Now in bp_activity table, i have the 2 metas for 2 different activities, let's say :

  • activity 19 has a 'test' meta_key with the value of 1
  • activity 18 has a 'rand' meta_key with the value of 2

The result is ok, it displays activities 19 && 18

Now if activity 19 has a 'test' meta_key with the value of 1 and a 'rand' meta_key with the value of 2, then the result is not ok as it displays the activity 19 three times.

Change History (4)

#1 @boonebgorges
11 years ago

  • Milestone changed from Awaiting Review to 1.9
  • Priority changed from normal to high

Confirmed. We ought to be doing a DISTINCT check in our queries. We've never really had reason to ensure distinct before, but here we do.

Because it's possible that the DISTINCT check will break some stuff, I'm going to put this in the 1.9 milestone. What imath is doing here, while definitely legitimate, is hopefully an edge case.

#2 @boonebgorges
11 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 7318:

Enforce DISTINCT in BP_Activity_Activity::get() queries

Previously, we've never really needed to state DISTINCT explicitly in
BP_Activity_Activity::get(), because the kinds of queries we ran would
naturally result in the exclusion of duplicates. The introduction of
the meta_query parameter in 1.8 - and in particular, the ability to
introduce more than one meta_query clause separated by the inclusive
OR relation - uncovered the bug, as single activity items were matching
more than one clause in the meta_query and thus being returned in the
results more than once.

Fixes #5118

#3 @boonebgorges
11 years ago

  • Milestone changed from 1.9 to 1.8.1

Following up on the logic described in #5119, I've reconsidered my position on backward compatibility here - I think the possibility of breaking things with the new DISTINCT keyword is very slight (could only happen for very specific kinds of filters on the activity queries). On the other hand, the meta_query paramater here is of pretty limited use if the fix is not resolved for 1.8.1. So I'm going to move it to the 1.8 branch as well.

#4 @boonebgorges
11 years ago

In 7324:

Enforce DISTINCT in BP_Activity_Activity::get() queries

Previously, we've never really needed to state DISTINCT explicitly in
BP_Activity_Activity::get(), because the kinds of queries we ran would
naturally result in the exclusion of duplicates. The introduction of
the meta_query parameter in 1.8 - and in particular, the ability to
introduce more than one meta_query clause separated by the inclusive
OR relation - uncovered the bug, as single activity items were matching
more than one clause in the meta_query and thus being returned in the
results more than once.

Fixes #5118

Note: See TracTickets for help on using tickets.