Add LocalSite.objects.build_q, for optimized LocalSite querying.

Review Request #12355 — Created June 10, 2022 and submitted

Information

Review Board
release-5.0.x

Reviewers

This introduces LocalSite.objects.build_q(), which builds a Q()
result based on the provided LocalSite/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 empty Q(), 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
Add LocalSite.objects.build_q, for optimized LocalSite querying.
This introduces `LocalSite.objects.build_q()`, which builds a `Q()` result based on the provided `LocalSite`/`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 empty `Q()`, which will be optimized out when joining with another. If Local Sites are used, this will construct a `Q(local_site=...)` value. 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.
cfae27a138363aa8b2c6f804b0753ea3ac43e351
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-5.0.x (8872035)
Loading...