Reduce queries and JOINs in LocalSiteManager.
Review Request #12353 — Created June 10, 2022 and submitted
LocalSite.objects.get_stats()now performs the total and public
LocalSitecounts in one query instead of two, leveraging
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
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
throughtables 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.