Skip to content

Commit e772441

Browse files
committed
chore(cleanup): Fix File cleanup job timeouts
The File cleanup job was timing out trying to fetch by ordering the timestamp field which has no index in US. Switched to ordering by ID which is performant. This will cause us to always go through entire table in chunks but we want to do that right now. Once we cleaned a lot of rows we can add an index and revert. Also corrected the child_relation to use ModelRelation type
1 parent 6e307dd commit e772441

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/sentry/deletions/defaults/file.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.db.models import Q
44
from django.utils import timezone
55

6-
from sentry.deletions.base import BaseRelation, ModelDeletionTask
6+
from sentry.deletions.base import BaseRelation, ModelDeletionTask, ModelRelation
77
from sentry.models.files.file import File
88

99

@@ -37,8 +37,5 @@ def get_child_relations(self, instance: File) -> list[BaseRelation]:
3737
from sentry.models.files.fileblobindex import FileBlobIndex
3838

3939
return [
40-
BaseRelation(
41-
params={"model": FileBlobIndex, "query": {"file_id": instance.id}},
42-
task=None, # Use BulkModelDeletionTask
43-
),
40+
ModelRelation(FileBlobIndex, {"file_id": instance.id}),
4441
]

src/sentry/runner/commands/cleanup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def models_which_use_deletions_code_path() -> list[tuple[type[Model], str, str]]
535535
(PullRequest, "date_added", "date_added"),
536536
(RuleFireHistory, "date_added", "date_added"),
537537
(Release, "date_added", "date_added"),
538-
(File, "timestamp", "timestamp"),
538+
(File, "timestamp", "id"),
539539
(Commit, "date_added", "id"),
540540
]
541541

@@ -548,7 +548,7 @@ def remove_cross_project_models(
548548

549549
# These models span across projects, so let's skip them
550550
deletes.remove((ArtifactBundle, "date_added", "date_added"))
551-
deletes.remove((File, "timestamp", "timestamp"))
551+
deletes.remove((File, "timestamp", "id"))
552552
return deletes
553553

554554

0 commit comments

Comments
 (0)