Massively reduce query counts when performing search indexes.

Review Request #8918 — Created May 1, 2017 and submitted

Christian Hammond
Review Board

We were performing numerous queries for every user or review request
being indexed. This led to slowdowns when performing large indexes, or
on slower search backends.

We now make full use of select_related() and prefetch_related(),
iterating over the cached results instead of performing new queries to
filter content.

For 100 users, this should reduce the query count from 201 queries to 3.
For 100 review requests, the query count should be reduced from 402 to

Tested a full search index with queries turned on. Saw that we no longer
had per-item queries, and that all content was being indexed properly.

David Trowbridge
  1. Ship It!
Christian Hammond
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-2.5.x (a7f50fc)