create_order_transactions: Make suitable for large datasets

This commit is contained in:
Raphael Michel
2021-10-19 15:25:34 +02:00
parent 0c25b2df92
commit 19fb6c8c34

View File

@@ -53,8 +53,17 @@ 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
with tqdm(total=qs.count()) as pbar:
while True:
batch = list(qs.filter(pk__gt=last_pk)[:5000])
if not batch:
break
for o in batch:
if o.last_transaction is None: if o.last_transaction is None:
tn = o.create_transactions( tn = o.create_transactions(
positions=o.all_positions.all(), positions=o.all_positions.all(),
@@ -79,6 +88,8 @@ class Command(BaseCommand):
) )
if tn: if tn:
t += 1 t += 1
time.sleep(options.get('slowdown', 0) / 1000) 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.'))