Refactor scope queryset subfilters to use UNION instead of a chain of ORs.
Refactor scope queryset subfilters to use UNION instead of a chain of ORs.

In one project this made the difference between "gateway timeout"
caused by a query that took 317 seconds and a query that took a few
microseconds...

It's a bit hard to predict whether this will always be the case, but I
think in most cases by pushing down the condition into a UNION query
with an "WHERE id IN (...)" around it the optimizer has more
opportunity to combine both expressions, so I am pretty confident that
it should be faster in the majority of cases.

CodeYellowBV/django-binder