Commit 4e55e31c by Ahsan Ulhaq Committed by Ahsan Ul Haq

Moved sleep from atomic block in clean history command

Moved the sleep outside atomic block and added logs to keep
track of deleted history records.

LEARNER-2697
parent 59f94185
...@@ -70,9 +70,14 @@ class Command(BaseCommand): ...@@ -70,9 +70,14 @@ class Command(BaseCommand):
qs = qs[:batch_size] qs = qs[:batch_size]
while qs.exists(): while qs.exists():
history_batch = qs.values_list('id', flat=True) history_batch = list(qs.values_list('id', flat=True))
with transaction.atomic(): with transaction.atomic():
model.history.filter(pk__in=list(history_batch)).delete() model.history.filter(pk__in=history_batch).delete()
time.sleep(sleep_time) logger.info(
'Deleted instances of %s with PKs between %d and %d',
model.__name__, history_batch[0], history_batch[-1]
)
time.sleep(sleep_time)
qs = model.history.filter(history_date__lte=cutoff_date)[:batch_size] qs = model.history.filter(history_date__lte=cutoff_date)[:batch_size]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment