Optimize search indexing for review requests.

Review Request #13388 — Created Oct. 30, 2023 and submitted — Latest diff uploaded

Information

Review Board
release-5.0.x

Reviewers

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 DISTINCT after 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
another prefetch_related relation 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
excess queries.

Commits

Files

    Loading...