2
0
Fork 0

vastly reduce page view queries, cache common data

This commit is contained in:
Andreas (@xAndy) Zimmermann 2023-05-28 11:56:40 +02:00
parent e01e04fe87
commit a3ac897055
2 changed files with 10 additions and 4 deletions

View File

@ -46,7 +46,7 @@ class Shift(models.Model):
)
),
)
)
).select_related("room")
def __str__(self):
return f"{self.room.name}: {self.start_at}"

View File

@ -2,6 +2,7 @@ from django.shortcuts import render, redirect, get_object_or_404
from .models import Shift, LoginToken, Helper, ShiftRegistration
from django.db import transaction
from django.db.models import F, Count, Q, ExpressionWrapper
from django.core.cache import cache
from .forms import RegisterForm, EmptyForm, AstaForm
from django.db.models.fields import DateTimeField
from datetime import timedelta
@ -21,8 +22,13 @@ def index(request):
if request.session.get("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 = {
"days": Shift.objects.filter(deleted=False).datetimes("start_at", "day"),
"days": days,
"enable_asta": global_preferences["helper__enable_asta"],
}
@ -58,7 +64,7 @@ def index(request):
deleted=False,
)
.order_by("start_at")
for day in Shift.objects.datetimes("start_at", "day")
for day in days
)
if request.helper:
free_shifts = (
@ -175,7 +181,7 @@ def register(request):
@event_state
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
context = {
"enable_asta": global_preferences["helper__enable_asta"],