vastly reduce page view queries, cache common data
This commit is contained in:
parent
e01e04fe87
commit
a3ac897055
|
@ -46,7 +46,7 @@ class Shift(models.Model):
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
).select_related("room")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.room.name}: {self.start_at}"
|
return f"{self.room.name}: {self.start_at}"
|
||||||
|
|
|
@ -2,6 +2,7 @@ from django.shortcuts import render, redirect, get_object_or_404
|
||||||
from .models import Shift, LoginToken, Helper, ShiftRegistration
|
from .models import Shift, LoginToken, Helper, ShiftRegistration
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import F, Count, Q, ExpressionWrapper
|
from django.db.models import F, Count, Q, ExpressionWrapper
|
||||||
|
from django.core.cache import cache
|
||||||
from .forms import RegisterForm, EmptyForm, AstaForm
|
from .forms import RegisterForm, EmptyForm, AstaForm
|
||||||
from django.db.models.fields import DateTimeField
|
from django.db.models.fields import DateTimeField
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
@ -21,8 +22,13 @@ def index(request):
|
||||||
if request.session.get("last_seen_shift"):
|
if request.session.get("last_seen_shift"):
|
||||||
del request.session["last_seen_shift"]
|
del request.session["last_seen_shift"]
|
||||||
|
|
||||||
|
days = cache.get("event_days")
|
||||||
|
if not days:
|
||||||
|
days = Shift.objects.filter(deleted=False).datetimes("start_at", "day").all()
|
||||||
|
cache.set("event_days", days)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"days": Shift.objects.filter(deleted=False).datetimes("start_at", "day"),
|
"days": days,
|
||||||
"enable_asta": global_preferences["helper__enable_asta"],
|
"enable_asta": global_preferences["helper__enable_asta"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +64,7 @@ def index(request):
|
||||||
deleted=False,
|
deleted=False,
|
||||||
)
|
)
|
||||||
.order_by("start_at")
|
.order_by("start_at")
|
||||||
for day in Shift.objects.datetimes("start_at", "day")
|
for day in days
|
||||||
)
|
)
|
||||||
if request.helper:
|
if request.helper:
|
||||||
free_shifts = (
|
free_shifts = (
|
||||||
|
@ -175,7 +181,7 @@ def register(request):
|
||||||
|
|
||||||
@event_state
|
@event_state
|
||||||
def shift(request, shiftid):
|
def shift(request, shiftid):
|
||||||
shift = get_object_or_404(Shift, pk=shiftid)
|
shift = get_object_or_404(Shift.with_reg_count(), pk=shiftid)
|
||||||
helper = request.helper
|
helper = request.helper
|
||||||
context = {
|
context = {
|
||||||
"enable_asta": global_preferences["helper__enable_asta"],
|
"enable_asta": global_preferences["helper__enable_asta"],
|
||||||
|
|
Loading…
Reference in New Issue