Optimize search indexing for review requests.

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

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.

Summary ID
Optimize search indexing for review requests.
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.
3c2b9adb8f7382f3c7516ce375170adf41495e3d
david
  1. Ship It!
  2. 
      
maubin
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-5.0.x (f65c621)