Optimize search indexing for review requests.
Review Request #13388 — Created Oct. 30, 2023 and submitted
The indexing queryset for review requests was hitting the same issue we
saw with datagrids and the API where a
SELECT COUNT(*)would end up
performing a very expensive nested query, due to the usage of
DISTINCT. We have plans to remove
DISTINCTafter some further
testing, but probably not until Review Board 7.
However, we can now turn it off, if we don't mind the chance of
duplicates. That is fine for search indexing, since any duplicates will
just collapse into one entry.
This change turns off distinct queries when indexing, and also adds
prefetch_relatedrelation to pre-fetch diffsets. This reduces
the overall number of queries when indexing a batch of review requests.
Unit tests pass.
Tested building a full search index and inspecting all the generated
SQL queries, making sure we were performing simple queries and avoiding