New attempt at improving CheckinList.checkin_count

This commit is contained in:
Raphael Michel
2020-07-24 15:41:41 +02:00
parent 0a2346778d
commit 1fb861a117

View File

@@ -3,7 +3,7 @@ from django.db import models
from django.db.models import Exists, F, Max, OuterRef, Q, Subquery
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _, pgettext_lazy
from django_scopes import ScopedManager
from django_scopes import ScopedManager, scopes_disabled
from jsonfallback.fields import FallbackJSONField
from pretix.base.models import LoggedModel
@@ -90,6 +90,9 @@ class CheckinList(LoggedModel):
).count()
@property
@scopes_disabled()
# Disable scopes, because this query is safe and the additional organizer filter in the EXISTS() subquery tricks PostgreSQL into a bad
# subplan that sequentially scans all events
def checkin_count(self):
return self.event.cache.get_or_set(
'checkin_list_{}_checkin_count'.format(self.pk),