Avoid too many User queries when calculating ReviewRequestPageData state.

Review Request #14316 — Created Jan. 30, 2025 and submitted — Latest diff uploaded

Information

Review Board
release-7.1.x

Reviewers

We query a lot of objects in ReviewRequestPageData, and many of these
have User objects associated. These end up being queried as separate
instances, which means that we lose out on any caching of profiles. This
ultimately leads to a lot of extra SQL queries per page.

We now determine all the users we know we have up-front, and then query
for for anything we're missing. Once we know we have all the users, we
re-attach the instances to the fetched objects, allowing the same
instances and cached state to be reused.

Unit tests pass.

Verified that the SQL queries on some test review requests have been
reduced.

Changes between revision 1 and 2

orig
1
2

Commits

Summary ID Author
Avoid too many User queries when calculating ReviewRequestPageData state.
We query a lot of objects in `ReviewRequestPageData`, and many of these have `User` objects associated. These end up being queried as separate instances, which means that we lose out on any caching of profiles. This ultimately leads to a lot of extra SQL queries per page. We now determine all the users we know we have up-front, and then query for for anything we're missing. Once we know we have all the users, we re-attach the instances to the fetched objects, allowing the same instances and cached state to be reused.
371926ad05b6284d04767b181353991db15fdc95 Christian Hammond
Avoid too many User queries when calculating ReviewRequestPageData state.
We query a lot of objects in `ReviewRequestPageData`, and many of these have `User` objects associated. These end up being queried as separate instances, which means that we lose out on any caching of profiles. This ultimately leads to a lot of extra SQL queries per page. We now determine all the users we know we have up-front, and then query for for anything we're missing. Once we know we have all the users, we re-attach the instances to the fetched objects, allowing the same instances and cached state to be reused.
6a5049fa4e2b6c3cfc3977254a9da178253945bf Christian Hammond
reviewboard/reviews/detail.py
reviewboard/reviews/tests/test_review_request_page_data.py
Loading...