mark_order_paid: Only lock when necessary

This commit is contained in:
Raphael Michel
2016-11-27 16:13:58 +01:00
parent 4d916df7c0
commit 4f6eb903c7
2 changed files with 12 additions and 4 deletions
+4 -3
View File
@@ -279,12 +279,13 @@ class Order(LoggedModel):
if now() > last_date:
return error_messages['late']
if self.status == self.STATUS_PENDING:
return True
if not self.event.settings.get('payment_term_accept_late'):
return error_messages['late']
return self._is_still_available()
if self.status == self.STATUS_PENDING:
return True
else:
return self._is_still_available()
def _is_still_available(self, now_dt: datetime=None) -> Union[bool, str]:
error_messages = {
+8 -1
View File
@@ -82,7 +82,14 @@ def mark_order_paid(order: Order, provider: str=None, info: str=None, date: date
:param user: The user that performed the change
:raises Quota.QuotaExceededException: if the quota is exceeded and ``force`` is ``False``
"""
with order.event.lock() as now_dt:
lock_func = order.event.lock
if order.status == order.STATUS_PENDING and order.expires > now() + timedelta(minutes=10):
# No lock necessary in this case. The 10 minute offset is just to be safe and prevent
# collisions with the cronjob.
def lock_func():
return now()
with lock_func() as now_dt:
can_be_paid = order._can_be_paid()
if not force and can_be_paid is not True:
raise Quota.QuotaExceededException(can_be_paid)