Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Remove unnecessary tasks (not referenced anywhere anymore and also (#17921)
Marcin Wcisłof3cad6f225b7
diff --git a/saleor/checkout/migrations/tasks/saleor3_14.py b/saleor/checkout/migrations/tasks/saleor3_14.pydeleted file mode 100644index 8f4ee10713..0000000000--- a/saleor/checkout/migrations/tasks/saleor3_14.py+++ /dev/null@@ -1,64 +0,0 @@-from django.db import transaction-from django.db.models.expressions import Exists, OuterRef, Q--from ....celeryconf import app-from ....core.db.connection import allow_writer-from ....payment.models import TransactionItem-from ...models import Checkout--# It takes less that a second to process the batch.-# The memory usage peak on celery worker was around 40MB.-BATCH_SIZE = 2000---@allow_writer()-def update_transaction_modified_at_in_checkouts():- checkouts_without_modified_at = Checkout.objects.filter(- Exists(TransactionItem.objects.filter(checkout_id=OuterRef("pk"))),- last_transaction_modified_at__isnull=True,- ).values_list("pk", flat=True)[:BATCH_SIZE]-- if checkouts_without_modified_at:- checkouts = Checkout.objects.filter(- pk__in=checkouts_without_modified_at- ).prefetch_related("payment_transactions")- checkouts_to_update = []- for checkout in checkouts:- payment_transactions = list(checkout.payment_transactions.all())- last_transaction = sorted(- payment_transactions, key=lambda t: t.modified_at- )[-1]- checkout.last_transaction_modified_at = last_transaction.modified_at- checkouts_to_update.append(checkout)- with transaction.atomic():- # lock the batch of objects- # multiple celery migration tasks called for the same model can cause- # deadlock. Before updating the objects we need to lock them.- _checkouts_lock = list(checkouts.select_for_update(of=(["self"])))- Checkout.objects.bulk_update(- checkouts_to_update, ["last_transaction_modified_at"]- )- update_transaction_modified_at_in_checkouts.delay()---@allow_writer()-def update_checkout_refundable():- with_transactions = TransactionItem.objects.filter(- Q(checkout_id=OuterRef("pk"))- & (Q(authorized_value__gt=0) | Q(charged_value__gt=0))- )- checkout_to_update = Checkout.objects.filter(- Exists(with_transactions), automatically_refundable=False- ).values_list("pk", flat=True)[:BATCH_SIZE]-- if checkout_to_update:- with transaction.atomic():- # lock the batch of objects- # multiple celery migration tasks called for the same model can cause- # deadlock. Before updating the objects we need to lock them.- _checkout_lock = list(checkout_to_update.select_for_update(of=(["self"])))- checkout_to_update.update(automatically_refundable=True)-- update_checkout_refundable.delay()diff --git a/saleor/payment/migrations/tasks/saleor3_19.py b/saleor/payment/migrations/tasks/saleor3_19.pydeleted file mode 100644index fa7bb2f00b..0000000000--- a/saleor/payment/migrations/tasks/saleor3_19.py+++ /dev/null@@ -1,53 +0,0 @@-from django.db import transaction-from django.db.models import Exists, OuterRef--from ....celeryconf import app-from ....core.db.connection import allow_writer-from ... import ChargeStatus-from ...models import Payment--# Batch size of size 3000 took about 0.2s and consume about 5MB memory usage-PAYMENT_BATCH_SIZE = 3000---@allow_writer()-def fix_invalid_atobarai_payments_task():- """Fix the invalid payemnts for atobarai gateway.-- Some orders has inactive charged payments and active not charged payments.- The task will activate the charged payments and deactivate the not charged payments.- """- not_charged_active_payments = Payment.objects.filter(- is_active=True,- charge_status=ChargeStatus.NOT_CHARGED,- captured_amount=0,- gateway="saleor.payments.np-atobarai",- )- payments_to_activate_ids = list(- Payment.objects.filter(- Exists(not_charged_active_payments.filter(order_id=OuterRef("order_id"))),- is_active=False,- charge_status__in=[- ChargeStatus.FULLY_CHARGED,- ChargeStatus.PARTIALLY_CHARGED,- ],- captured_amount__gt=0,- gateway="saleor.payments.np-atobarai",- ).values_list("pk", flat=True)[:PAYMENT_BATCH_SIZE]- )- if payments_to_activate_ids:- payments_to_activate = Payment.objects.filter(pk__in=payments_to_activate_ids)-- related_order_ids = payments_to_activate.values("order_id")- payments_to_deactivate = Payment.objects.filter(- order_id__in=related_order_ids, is_active=True- ).exclude(pk__in=payments_to_activate_ids)-- with transaction.atomic():- qs = payments_to_deactivate | payments_to_activate- _payments = list(qs.select_for_update(of=(["self"])))- payments_to_deactivate.update(is_active=False)- payments_to_activate.update(is_active=True)-- fix_invalid_atobarai_payments_task.delay()