Use database replica for check-in count for statistical purposes

This commit is contained in:
Raphael Michel
2020-07-23 17:48:31 +02:00
parent 4968a6d995
commit 829b0041fc

View File

@@ -1,3 +1,4 @@
from django.conf import settings
from django.db import models from django.db import models
from django.db.models import Exists, F, Max, OuterRef, Q, Subquery from django.db.models import Exists, F, Max, OuterRef, Q, Subquery
from django.utils.timezone import now from django.utils.timezone import now
@@ -92,7 +93,7 @@ class CheckinList(LoggedModel):
def checkin_count(self): def checkin_count(self):
return self.event.cache.get_or_set( return self.event.cache.get_or_set(
'checkin_list_{}_checkin_count'.format(self.pk), 'checkin_list_{}_checkin_count'.format(self.pk),
lambda: self.positions.annotate( lambda: self.positions.using(settings.DATABASE_REPLICA).annotate(
checkedin=Exists(Checkin.objects.filter(list_id=self.pk, position=OuterRef('pk'), type=Checkin.TYPE_ENTRY,)) checkedin=Exists(Checkin.objects.filter(list_id=self.pk, position=OuterRef('pk'), type=Checkin.TYPE_ENTRY,))
).filter( ).filter(
checkedin=True checkedin=True