Add LocalSite.objects.build_q, for optimized LocalSite querying.
Review Request #12355 — Created June 10, 2022 and submitted
This introduces
LocalSite.objects.build_q()
, which builds aQ()
result based on the providedLocalSite
/LocalSite.ALL
value and
whether Local Site functionality is used in the deployment.If either
LocalSite.ALL
is passed or Local Sites are not in use, the
result will be an emptyQ()
, which will be optimized out when joining
with another.If Local Sites are used, this will construct a
Q(local_site=...)
value.It also provides validation on arguments, ensuring that a
LocalSite
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.
Summary | ID |
---|---|
cfae27a138363aa8b2c6f804b0753ea3ac43e351 |