#5099 closed defect (bug) (fixed)
Total groups wrong when fetching groups with meta query
Reported by: | r-a-y | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 2.7 | Priority: | normal |
Severity: | normal | Version: | 1.8 |
Component: | Groups | Keywords: | |
Cc: |
Description
Using bp_has_groups()
with the new meta_query
parameter works well, however the total groups returned is wrong.
Attached is a unit test. Will have a patch up soon.
Attachments (3)
Change History (19)
#2
follow-up:
↓ 3
@
11 years ago
Good catch, r-a-y.
I agree that the way we're assembling the total count here is not ideal. Your patch seems like a good way forward in the future (though we can probably also snip LIMIT and ORDER BY clauses as well). But, as you note, it's a big change for 1.8. And since the bug is with a feature that is being introduced for the first time in 1.8 (ie, this is neither a regression nor a longtime bug), it seems fine to me to put a band-aid on it for now, as in 5099.02.patch. Then, for 1.9, we can circle back around to your more general suggestion.
Have a look at 5099.02.patch and let me know what you think.
#3
in reply to:
↑ 2
@
11 years ago
Replying to boonebgorges:
Have a look at 5099.02.patch and let me know what you think.
Looks like a good enough work around for me. We could move Ray's larger fix to 1.8.1 when it's time, also.
#4
@
11 years ago
02.patch works for me.
And, Boone, you're right we should remove the LIMIT and ORDER BY clauses when we look at 01.patch again later on.
#8
@
11 years ago
- Milestone changed from 1.8 to 1.9
Moving to 1.9 so we can address the larger issue of how the total group count query is assembled.
01.patch changes the way the groups total SQL statement is generated.
Before, we used two different SQL statements in
BP_Groups_Group::get()
. One for the paged groups and the other for total groups. This isn't so great as changes in one SQL statement will need to be mirrored in the other, which can lead to inaccuracies. The new meta query parameter outlines this problem.Instead of fiddling around with the total groups SQL to work with the meta query parameter, the attached patch uses the paged SQL statement to generate the total groups SQL statement. See line 451 of the patch.
Because of this, the
$total_sql
array is now not used. However, for plugin devs using$total_sql
in the'bp_groups_get_total_groups_sql'
filter, we still need to keep it for the time being. So, I've introduced a new method -get_deprecated_total_groups_sql()
- to move the old code away from theget()
method with the hopes of removing it later.Patch passes the unit test attached to this ticket. However, this could use more testing.
I know this is quite a big change, but I think this is cleaner and makes more sense. Feel free to implement an alternative fix if this is deemed too radical a change as 1.8 is due to hit some time very soon.