forked from CGM_Public/pretix_original
Experimental caching for the number of paid tickets
This commit is contained in:
@@ -875,7 +875,7 @@ class Item(Versionable):
|
|||||||
self.variations.annotate(
|
self.variations.annotate(
|
||||||
qc=Count('quotas')
|
qc=Count('quotas')
|
||||||
).filter(qc__gt=0).prefetch_related(
|
).filter(qc__gt=0).prefetch_related(
|
||||||
"values", "values__prop"
|
"values", "values__prop", "quotas__event"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
variations = []
|
variations = []
|
||||||
@@ -1215,6 +1215,7 @@ class Quota(Versionable):
|
|||||||
# TODO: Test for interference with old versions of Item-Quota-relations, etc.
|
# 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
|
# TODO: Prevent corner-cases like people having ordered an item before it got
|
||||||
# its first variationsadded
|
# its first variationsadded
|
||||||
|
cache = self.event.get_cache()
|
||||||
quotalookup = (
|
quotalookup = (
|
||||||
( # Orders for items which do not have any variations
|
( # Orders for items which do not have any variations
|
||||||
Q(variation__isnull=True)
|
Q(variation__isnull=True)
|
||||||
@@ -1223,10 +1224,15 @@ class Quota(Versionable):
|
|||||||
Q(variation__quotas__in=[self])
|
Q(variation__quotas__in=[self])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
paid_orders = OrderPosition.objects.current.filter(
|
|
||||||
Q(order__status=Order.STATUS_PAID)
|
paid_orders = cache.get('quota_paid_%s' % self.identity)
|
||||||
& quotalookup
|
if paid_orders is None:
|
||||||
).count()
|
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:
|
if paid_orders >= self.size:
|
||||||
return Quota.AVAILABILITY_GONE, 0
|
return Quota.AVAILABILITY_GONE, 0
|
||||||
|
|
||||||
@@ -1290,6 +1296,7 @@ class Quota(Versionable):
|
|||||||
)
|
)
|
||||||
self.locked_here = None
|
self.locked_here = None
|
||||||
self.locked = None
|
self.locked = None
|
||||||
|
self.event.get_cache().delete('quota_paid_%s' % self.identity)
|
||||||
return updated
|
return updated
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class EventIndex(EventViewMixin, CartDisplayMixin, TemplateView):
|
|||||||
'category', # for re-grouping
|
'category', # for re-grouping
|
||||||
).prefetch_related(
|
).prefetch_related(
|
||||||
'properties', # for .get_all_available_variations()
|
'properties', # for .get_all_available_variations()
|
||||||
'quotas', 'variations__quotas' # for .availability()
|
'quotas', 'variations__quotas', 'quotas__event' # for .availability()
|
||||||
).annotate(quotac=Count('quotas')).filter(
|
).annotate(quotac=Count('quotas')).filter(
|
||||||
quotac__gt=0
|
quotac__gt=0
|
||||||
).order_by('category__position', 'category_id', 'name')
|
).order_by('category__position', 'category_id', 'name')
|
||||||
|
|||||||
Reference in New Issue
Block a user