mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Reduce number of redundant SQL queries
This commit is contained in:
@@ -91,14 +91,16 @@ class BaseCheckoutFlowStep:
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def invoice_address(self):
|
def invoice_address(self):
|
||||||
iapk = self.cart_session.get('invoice_address')
|
if not hasattr(self.request, '_checkout_flow_invoice_address'):
|
||||||
if not iapk:
|
iapk = self.cart_session.get('invoice_address')
|
||||||
return InvoiceAddress()
|
if not iapk:
|
||||||
|
self.request._checkout_flow_invoice_address = InvoiceAddress()
|
||||||
try:
|
else:
|
||||||
return InvoiceAddress.objects.get(pk=iapk, order__isnull=True)
|
try:
|
||||||
except InvoiceAddress.DoesNotExist:
|
self.request._checkout_flow_invoice_address = InvoiceAddress.objects.get(pk=iapk, order__isnull=True)
|
||||||
return InvoiceAddress()
|
except InvoiceAddress.DoesNotExist:
|
||||||
|
self.request._checkout_flow_invoice_address = InvoiceAddress()
|
||||||
|
return self.request._checkout_flow_invoice_address
|
||||||
|
|
||||||
|
|
||||||
def get_checkout_flow(event):
|
def get_checkout_flow(event):
|
||||||
@@ -160,7 +162,9 @@ class AddOnsStep(CartMixin, AsyncAction, TemplateFlowStep):
|
|||||||
requires_valid_cart = False
|
requires_valid_cart = False
|
||||||
|
|
||||||
def is_applicable(self, request):
|
def is_applicable(self, request):
|
||||||
return get_cart(request).filter(item__addons__isnull=False).exists()
|
if not hasattr(request, '_checkoutflow_addons_applicable'):
|
||||||
|
request._checkoutflow_addons_applicable = get_cart(request).filter(item__addons__isnull=False).exists()
|
||||||
|
return request._checkoutflow_addons_applicable
|
||||||
|
|
||||||
def is_completed(self, request, warn=False):
|
def is_completed(self, request, warn=False):
|
||||||
for cartpos in get_cart(request).filter(addon_to__isnull=True).prefetch_related(
|
for cartpos in get_cart(request).filter(addon_to__isnull=True).prefetch_related(
|
||||||
|
|||||||
@@ -24,6 +24,19 @@ class CartMixin:
|
|||||||
from pretix.presale.views.cart import cart_session
|
from pretix.presale.views.cart import cart_session
|
||||||
return cart_session(self.request)
|
return cart_session(self.request)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def invoice_address(self):
|
||||||
|
if not hasattr(self.request, '_checkout_flow_invoice_address'):
|
||||||
|
iapk = self.cart_session.get('invoice_address')
|
||||||
|
if not iapk:
|
||||||
|
self.request._checkout_flow_invoice_address = InvoiceAddress()
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.request._checkout_flow_invoice_address = InvoiceAddress.objects.get(pk=iapk, order__isnull=True)
|
||||||
|
except InvoiceAddress.DoesNotExist:
|
||||||
|
self.request._checkout_flow_invoice_address = InvoiceAddress()
|
||||||
|
return self.request._checkout_flow_invoice_address
|
||||||
|
|
||||||
def get_cart(self, answers=False, queryset=None, order=None, downloads=False):
|
def get_cart(self, answers=False, queryset=None, order=None, downloads=False):
|
||||||
if queryset:
|
if queryset:
|
||||||
prefetch = []
|
prefetch = []
|
||||||
@@ -107,15 +120,7 @@ class CartMixin:
|
|||||||
if order:
|
if order:
|
||||||
fees = order.fees.all()
|
fees = order.fees.all()
|
||||||
else:
|
else:
|
||||||
iapk = self.cart_session.get('invoice_address')
|
fees = get_fees(self.request.event, self.request, total, self.invoice_address, self.cart_session.get('payment'))
|
||||||
ia = None
|
|
||||||
if iapk:
|
|
||||||
try:
|
|
||||||
ia = InvoiceAddress.objects.get(pk=iapk, order__isnull=True)
|
|
||||||
except InvoiceAddress.DoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
fees = get_fees(self.request.event, self.request, total, ia, self.cart_session.get('payment'))
|
|
||||||
|
|
||||||
total += sum([f.value for f in fees])
|
total += sum([f.value for f in fees])
|
||||||
net_total += sum([f.net_value for f in fees])
|
net_total += sum([f.net_value for f in fees])
|
||||||
|
|||||||
@@ -4,23 +4,19 @@ from django.shortcuts import redirect
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.views.generic import View
|
from django.views.generic import View
|
||||||
|
|
||||||
from pretix.base.models import CartPosition
|
|
||||||
from pretix.base.services.cart import CartError
|
from pretix.base.services.cart import CartError
|
||||||
from pretix.base.signals import validate_cart
|
from pretix.base.signals import validate_cart
|
||||||
from pretix.multidomain.urlreverse import eventreverse
|
from pretix.multidomain.urlreverse import eventreverse
|
||||||
from pretix.presale.checkoutflow import get_checkout_flow
|
from pretix.presale.checkoutflow import get_checkout_flow
|
||||||
from pretix.presale.views.cart import get_or_create_cart_id
|
from pretix.presale.views import get_cart
|
||||||
|
|
||||||
|
|
||||||
class CheckoutView(View):
|
class CheckoutView(View):
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
|
||||||
self.request = request
|
self.request = request
|
||||||
cart_pos = CartPosition.objects.filter(
|
|
||||||
cart_id=get_or_create_cart_id(request), event=self.request.event
|
|
||||||
)
|
|
||||||
|
|
||||||
if not cart_pos.exists() and "async_id" not in request.GET:
|
if not get_cart(request) and "async_id" not in request.GET:
|
||||||
messages.error(request, _("Your cart is empty"))
|
messages.error(request, _("Your cart is empty"))
|
||||||
return redirect(eventreverse(self.request.event, 'presale:event.index'))
|
return redirect(eventreverse(self.request.event, 'presale:event.index'))
|
||||||
|
|
||||||
@@ -30,7 +26,7 @@ class CheckoutView(View):
|
|||||||
|
|
||||||
cart_error = None
|
cart_error = None
|
||||||
try:
|
try:
|
||||||
validate_cart.send(sender=self.request.event, positions=cart_pos)
|
validate_cart.send(sender=self.request.event, positions=get_cart(request))
|
||||||
except CartError as e:
|
except CartError as e:
|
||||||
cart_error = e
|
cart_error = e
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user