Add LocalSite.objects.build_q, for optimized LocalSite querying.
Review Request #12355 — Created June 10, 2022 and submitted — Latest diff uploaded
LocalSite.objects.build_q(), which builds a
result based on the provided
whether Local Site functionality is used in the deployment.
LocalSite.ALLis passed or Local Sites are not in use, the
result will be an empty
Q(), which will be optimized out when joining
If Local Sites are used, this will construct a
It also provides validation on arguments, ensuring that a
instance cannot be accepted if the database does not contain any
Local Sites. This will mostly help us with writing correct tests and
to catch errors with stale caches.
This will greatly help us build queries in the most optimized way
possible. On normal deployments without Local Sites, these will be left
off entirely, allowing the database to make more optimized query plans.
Future changes will begin to introduce usage of this method.
Successfully made use of this in some in-progress changes, and
verified with those unit tests.