forked from CGM_Public/pretix_original
create_order_transactions: Make suitable for large datasets
This commit is contained in:
@@ -53,32 +53,43 @@ class Command(BaseCommand):
|
|||||||
require_approval=False,
|
require_approval=False,
|
||||||
).prefetch_related(
|
).prefetch_related(
|
||||||
'all_positions', 'all_fees'
|
'all_positions', 'all_fees'
|
||||||
|
).order_by(
|
||||||
|
'pk'
|
||||||
)
|
)
|
||||||
for o in tqdm(qs):
|
last_pk = 0
|
||||||
if o.last_transaction is None:
|
with tqdm(total=qs.count()) as pbar:
|
||||||
tn = o.create_transactions(
|
while True:
|
||||||
positions=o.all_positions.all(),
|
batch = list(qs.filter(pk__gt=last_pk)[:5000])
|
||||||
fees=o.all_fees.all(),
|
if not batch:
|
||||||
dt_now=o.datetime,
|
break
|
||||||
migrated=True,
|
|
||||||
is_new=True,
|
for o in batch:
|
||||||
_backfill_before_cancellation=True,
|
if o.last_transaction is None:
|
||||||
)
|
tn = o.create_transactions(
|
||||||
o.create_transactions(
|
positions=o.all_positions.all(),
|
||||||
positions=o.all_positions.all(),
|
fees=o.all_fees.all(),
|
||||||
fees=o.all_fees.all(),
|
dt_now=o.datetime,
|
||||||
dt_now=o.cancellation_date or (o.expires if o.status == Order.STATUS_EXPIRED else o.datetime),
|
migrated=True,
|
||||||
migrated=True,
|
is_new=True,
|
||||||
)
|
_backfill_before_cancellation=True,
|
||||||
else:
|
)
|
||||||
tn = o.create_transactions(
|
o.create_transactions(
|
||||||
positions=o.all_positions.all(),
|
positions=o.all_positions.all(),
|
||||||
fees=o.all_fees.all(),
|
fees=o.all_fees.all(),
|
||||||
dt_now=now(),
|
dt_now=o.cancellation_date or (o.expires if o.status == Order.STATUS_EXPIRED else o.datetime),
|
||||||
migrated=True,
|
migrated=True,
|
||||||
)
|
)
|
||||||
if tn:
|
else:
|
||||||
t += 1
|
tn = o.create_transactions(
|
||||||
time.sleep(options.get('slowdown', 0) / 1000)
|
positions=o.all_positions.all(),
|
||||||
|
fees=o.all_fees.all(),
|
||||||
|
dt_now=now(),
|
||||||
|
migrated=True,
|
||||||
|
)
|
||||||
|
if tn:
|
||||||
|
t += 1
|
||||||
|
time.sleep(0)
|
||||||
|
pbar.update(1)
|
||||||
|
last_pk = batch[-1].pk
|
||||||
|
|
||||||
self.stderr.write(self.style.SUCCESS(f'Created transactions for {t} orders.'))
|
self.stderr.write(self.style.SUCCESS(f'Created transactions for {t} orders.'))
|
||||||
|
|||||||
Reference in New Issue
Block a user