Skip to content

Commit

Permalink
Fix #1651, OOM kills during database cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aequitas committed Feb 19, 2025
1 parent 583c017 commit 846c143
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions interface/management/commands/database_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def handle(self, *args, **options):

# find all test probe results that have no report associated, but not too recent because
# those might be unfinished tests
count, _ = model.objects.filter(
domaintestreport__isnull=True, timestamp__lt=timestamp_recent_probes
).delete()
log.info("Deleted %s probes that don't have an associated report.", count)
# Using iterator, as delete() loads all objects into memory (for signals, cascades) and might cause a OOM kill
# https://docs.djangoproject.com/en/5.1/ref/models/querysets/#delete
count = 0
for obj in model.objects.filter(domaintestreport__isnull=True, timestamp__lt=timestamp_recent_probes).iterator():
obj.delete()
count += 1
log.info("Deleted %s %s probes that don't have an associated report.", model._meta.object_name, count)

0 comments on commit 846c143

Please sign in to comment.