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
LocalSite
counts in one query instead of two, leveragingaggregate()
andCount()
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 thethrough
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 |
---|---|
39b2424502cc5372800c105ff6e6322b4d661cef |