diff --git a/src/pretix/base/models.py b/src/pretix/base/models.py index bf117a574e..302a6f1e75 100644 --- a/src/pretix/base/models.py +++ b/src/pretix/base/models.py @@ -875,7 +875,7 @@ class Item(Versionable): self.variations.annotate( qc=Count('quotas') ).filter(qc__gt=0).prefetch_related( - "values", "values__prop" + "values", "values__prop", "quotas__event" ) ) variations = [] @@ -1215,6 +1215,7 @@ class Quota(Versionable): # TODO: Test for interference with old versions of Item-Quota-relations, etc. # TODO: Prevent corner-cases like people having ordered an item before it got # its first variationsadded + cache = self.event.get_cache() quotalookup = ( ( # Orders for items which do not have any variations Q(variation__isnull=True) @@ -1223,10 +1224,15 @@ class Quota(Versionable): Q(variation__quotas__in=[self]) ) ) - paid_orders = OrderPosition.objects.current.filter( - Q(order__status=Order.STATUS_PAID) - & quotalookup - ).count() + + paid_orders = cache.get('quota_paid_%s' % self.identity) + if paid_orders is None: + paid_orders = OrderPosition.objects.current.filter( + Q(order__status=Order.STATUS_PAID) + & quotalookup + ).count() + cache.set('quota_paid_%s' % self.identity, paid_orders) + if paid_orders >= self.size: return Quota.AVAILABILITY_GONE, 0 @@ -1290,6 +1296,7 @@ class Quota(Versionable): ) self.locked_here = None self.locked = None + self.event.get_cache().delete('quota_paid_%s' % self.identity) return updated diff --git a/src/pretix/presale/views/event.py b/src/pretix/presale/views/event.py index ad27dc3553..4a822196d0 100644 --- a/src/pretix/presale/views/event.py +++ b/src/pretix/presale/views/event.py @@ -25,7 +25,7 @@ class EventIndex(EventViewMixin, CartDisplayMixin, TemplateView): 'category', # for re-grouping ).prefetch_related( 'properties', # for .get_all_available_variations() - 'quotas', 'variations__quotas' # for .availability() + 'quotas', 'variations__quotas', 'quotas__event' # for .availability() ).annotate(quotac=Count('quotas')).filter( quotac__gt=0 ).order_by('category__position', 'category_id', 'name')