Skip to content

Commit 70d111d

Browse files
authored
fix(deletion): Delete group history in chunks (#89740)
Some groups have an excessive number of activity rows, and their deletion does not complete.
1 parent d4b9a17 commit 70d111d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/sentry/deletions/defaults/grouphistory.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ def chunk(self) -> bool:
2121
return super().chunk()
2222

2323
for group_id in group_ids:
24-
# Delete all history records for a single group
25-
self.model.objects.filter(group_id=group_id).delete()
24+
# Delete history records for a single group in chunks of 10000
25+
queryset = self.model.objects.filter(group_id=group_id)
26+
while True:
27+
# Get IDs for the first 10000 records
28+
chunk_ids = list(queryset.order_by("id").values_list("id", flat=True)[:10000])
29+
if not chunk_ids:
30+
break
31+
# Delete records for these IDs
32+
self.model.objects.filter(id__in=chunk_ids).delete()
2633

2734
return False

0 commit comments

Comments
 (0)