projectnami icon indicating copy to clipboard operation
projectnami copied to clipboard

Perform row count after any query filters have been run

Open rmc47 opened this issue 5 years ago • 0 comments

A proposed solution to #341, by performing the row count after any query filters have been run.

  • If any filters don't change the query, then it should have the same behaviour as before, constructing a COUNT() query from the constituent parts.
  • If filters do change the query:
    • If they leave the field list and order / group by clauses intact, we rewrite the filtered query into a COUNT() fairly safely
    • If the filters change the field list or order / group by clauses (not the case for bbPress), then rewriting it would be rather harder, and probably need a SQL parser. At the moment we just don't attempt to do it. One alternative would be to fall back to the old behaviour, but we wouldn't know if that result was correct or now. Another would be to bail out with an error, which would at least alert folks that something's likely to be incorrect.

I realise this is rather a chunk of change in the WP_Query class. Unfortunately I don't think it's possible to do the same in translations.php. Happy to look at other ways of doing this if you wish.

rmc47 avatar Mar 29 '19 12:03 rmc47