Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clear data store in chunks #119

Merged
merged 1 commit into from
Jul 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions silk/management/commands/silk_clear_request_log.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand

import silk.models

Expand All @@ -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