mirror of
https://github.com/pretix/pretix.git
synced 2026-05-10 16:04:02 +00:00
Further SQL optimizations
This commit is contained in:
@@ -2,7 +2,6 @@ from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import EmailValidator
|
||||
from django.db.models import Q, Sum
|
||||
from django.http import HttpResponseNotAllowed
|
||||
from django.shortcuts import redirect
|
||||
from django.utils import translation
|
||||
@@ -10,7 +9,7 @@ from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.generic.base import TemplateResponseMixin
|
||||
|
||||
from pretix.base.models import CartPosition, Order
|
||||
from pretix.base.models import Order
|
||||
from pretix.base.models.orders import InvoiceAddress
|
||||
from pretix.base.services.mail import SendMailException
|
||||
from pretix.base.services.orders import OrderError, perform_order
|
||||
@@ -18,7 +17,7 @@ from pretix.base.signals import register_payment_providers
|
||||
from pretix.multidomain.urlreverse import eventreverse
|
||||
from pretix.presale.forms.checkout import ContactForm, InvoiceAddressForm
|
||||
from pretix.presale.signals import checkout_flow_steps
|
||||
from pretix.presale.views import CartMixin
|
||||
from pretix.presale.views import CartMixin, get_cart_total
|
||||
from pretix.presale.views.async import AsyncAction
|
||||
from pretix.presale.views.questions import QuestionsViewMixin
|
||||
|
||||
@@ -143,11 +142,12 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
||||
|
||||
@cached_property
|
||||
def invoice_address(self):
|
||||
iapk = self.request.session.get('invoice_address')
|
||||
if not iapk:
|
||||
return InvoiceAddress()
|
||||
|
||||
try:
|
||||
return InvoiceAddress.objects.get(
|
||||
pk=self.request.session.get('invoice_address'),
|
||||
order__isnull=True
|
||||
)
|
||||
return InvoiceAddress.objects.get(pk=iapk, order__isnull=True)
|
||||
except InvoiceAddress.DoesNotExist:
|
||||
return InvoiceAddress()
|
||||
|
||||
@@ -218,9 +218,7 @@ class PaymentStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
||||
|
||||
@cached_property
|
||||
def _total_order_value(self):
|
||||
return CartPosition.objects.filter(
|
||||
Q(cart_id=self.request.session.session_key) & Q(event=self.request.event)
|
||||
).aggregate(sum=Sum('price'))['sum']
|
||||
return get_cart_total(self.request)
|
||||
|
||||
@cached_property
|
||||
def provider_forms(self):
|
||||
|
||||
@@ -2,6 +2,7 @@ from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
from itertools import groupby
|
||||
|
||||
from django.db.models import Sum
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.timezone import now
|
||||
|
||||
@@ -106,6 +107,17 @@ def get_cart(request):
|
||||
return request._cart_cache
|
||||
|
||||
|
||||
def get_cart_total(request):
|
||||
if not hasattr(request, '_cart_total_cache'):
|
||||
if hasattr(request, '_cart_cache'):
|
||||
request._cart_total_cache = sum(i.price for i in request._cart_cache)
|
||||
else:
|
||||
request._cart_total_cache = CartPosition.objects.filter(
|
||||
cart_id=request.session.session_key, event=request.event
|
||||
).aggregate(sum=Sum('price'))['sum']
|
||||
return request._cart_total_cache
|
||||
|
||||
|
||||
class EventViewMixin:
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
@@ -3,6 +3,7 @@ from django.utils.functional import cached_property
|
||||
|
||||
from pretix.base.models import CartPosition, OrderPosition, QuestionAnswer
|
||||
from pretix.presale.forms.checkout import QuestionsForm
|
||||
from pretix.presale.views import get_cart
|
||||
|
||||
|
||||
class QuestionsViewMixin:
|
||||
@@ -14,7 +15,7 @@ class QuestionsViewMixin:
|
||||
submitted at once.
|
||||
"""
|
||||
formlist = []
|
||||
for cr in self.positions:
|
||||
for cr in get_cart(self.request):
|
||||
cartpos = cr if isinstance(cr, CartPosition) else None
|
||||
orderpos = cr if isinstance(cr, OrderPosition) else None
|
||||
form = QuestionsForm(event=self.request.event,
|
||||
|
||||
Reference in New Issue
Block a user