Skip to content

Commit 5c7cdb1

Browse files
yuvmenshashjar
authored andcommitted
chore(cleanup): Fix File cleanup job timeouts (#102055)
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 2bc82c8 commit 5c7cdb1

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
@@ -538,7 +538,7 @@ def models_which_use_deletions_code_path() -> list[tuple[type[BaseModel], str, s
538538
(PullRequest, "date_added", "date_added"),
539539
(RuleFireHistory, "date_added", "date_added"),
540540
(Release, "date_added", "date_added"),
541-
(File, "timestamp", "timestamp"),
541+
(File, "timestamp", "id"),
542542
(Commit, "date_added", "id"),
543543
]
544544

@@ -551,7 +551,7 @@ def remove_cross_project_models(
551551

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

557557

0 commit comments

Comments
 (0)