Reduce queries and JOINs in LocalSiteManager.

Review Request #12353 — Created June 10, 2022 and submitted

Information

Review Board
release-5.0.x

Reviewers

LocalSite.objects.get_stats() now performs the total and public
LocalSite counts in one query instead of two, leveraging aggregate()
and Count() to get the totals. This can potentially be faster for
databases, allowing tables to be scanned just once instead of twice (if
needed). At worst, from testing, it doesn't appear to be any slower.

To ease some of this, we now have an index on LocalSite.public. This
can help databases determine a total without a scan.

LocalSite.objects.get_local_site_acl_stats() has also been optimized,
eliminating JOINs and instead using the through tables for user and
admin membership. This can make it much less expensive to get the IDs
from the database.

Successfully evolved the database.

Tested this query on SQLite and MySQL.

Unit tests pass.

Summary ID
Reduce queries and JOINs in LocalSiteManager.
`LocalSite.objects.get_stats()` now performs the total and public `LocalSite` counts in one query instead of two, leveraging `aggregate()` and `Count()` to get the totals. This can potentially be faster for databases, allowing tables to be scanned just once instead of twice (if needed). At worst, from testing, it doesn't appear to be any slower. To ease some of this, we now have an index on `LocalSite.public`. This can help databases determine a total without a scan. `LocalSite.objects.get_local_site_acl_stats()` has also been optimized, eliminating JOINs and instead using the `through` tables for user and admin membership. This can make it much less expensive to get the IDs from the database.
39b2424502cc5372800c105ff6e6322b4d661cef
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-5.0.x (25d43d8)
Loading...