From 1fb861a117d226d1b4e694a50458912e5396b17f Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Fri, 24 Jul 2020 15:41:41 +0200 Subject: [PATCH] New attempt at improving CheckinList.checkin_count --- src/pretix/base/models/checkin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pretix/base/models/checkin.py b/src/pretix/base/models/checkin.py index 78c859f00..18fed1c62 100644 --- a/src/pretix/base/models/checkin.py +++ b/src/pretix/base/models/checkin.py @@ -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),