Skip to content

Commit

Permalink
clear data store in chunks (#119)
Browse files Browse the repository at this point in the history
or else we'd get killed by OOM killer
  • Loading branch information
chrono authored and avelis committed Jul 6, 2016
1 parent 6f8a574 commit b3f27eb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions silk/management/commands/silk_clear_request_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ class Command(BaseCommand):

@staticmethod
def delete_model(model):
count = model.objects.count()
print("deleting %s %s objects" % (model.__name__, count))
model.objects.all().delete()
while True:
items_to_delete = list(
model.objects.values_list('pk', flat=True).all()[:1000])
if not items_to_delete:
break
model.objects.filter(pk__in=items_to_delete).delete()

def handle(self, *args, **options):
# Django takes a long time to traverse foreign key relations,
Expand Down

0 comments on commit b3f27eb

Please sign in to comment.