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

fix: recursively delete rows to prevent running out of memory in Request.garbage_collect (#711) #712

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion silk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ def garbage_collect(cls, force=False):

# Make sure we can delete everything if needed by settings
if target_count <= 0:
cls.objects.all().delete()
# delete every request older than now
time_cutoff = timezone.now()
# recursively delete every 10000 rows to prevent running out of memory
while cls.objects.filter(start_time__lte=time_cutoff).count() > 0:
pks = cls.objects.filter(start_time__lte=time_cutoff)[:10000].values_list('pk', flat=True)
cls.objects.filter(pk__in=pks).delete()
return

try:
Expand Down
Loading