toastdriven/django-haystack — pull request #947 by rouge8 (2014-02-20 05:03:39+00:00)
Title: Unify SearchQuerySet and RelatedSearchQuerySet

Fixes #370.

This patch eliminates the duplicated code between `SearchQuerySet` and `RelatedSearchQuerySet`. Previously, there was a lot of copy-paste with slight differences.

This was motivated by #370, as the difference between how `SearchQuerySet` and `RelatedSearchQuerySet` queried the backend for results made the `RelatedSearchQuerySet` extremely inefficient, since it would query `settings.ITERATOR_LOAD_PER_QUERY` records from the search engine at a time regardless of how many results were requested. This also meant any `select_related`/`prefetch_related` calls on the queryset would be need to be repeated against the database each time.

I haven't added a new test for this condition yet, but I tested it against my current project and many of the existing tests require fewer queries.