Reduce queries and JOINs in LocalSiteManager.

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

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.

Commits

Files

    Loading...