Skip to content

Commit 43ad56f

Browse files
authored
Builds: improve DB query for unhealthy builds (#12431)
Filter by `date` to use one of the fast DB indexes we have in the `Build` model. Solves https://read-the-docs.sentry.io/issues/6806637157/
1 parent cc69f23 commit 43ad56f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

readthedocs/projects/tasks/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ def finish_unhealthy_builds():
120120
"""
121121
log.debug("Running task to finish inactive builds (no healtcheck received).")
122122
delta = datetime.timedelta(seconds=settings.RTD_BUILD_HEALTHCHECK_TIMEOUT)
123-
query = ~Q(state__in=BUILD_FINAL_STATES) & Q(healthcheck__lt=timezone.now() - delta)
123+
query = (
124+
# Grab 3 days old at most to use a fast DB index
125+
Q(date__gt=timezone.now() - datetime.timedelta(days=3))
126+
& ~Q(state__in=BUILD_FINAL_STATES)
127+
& Q(healthcheck__lt=timezone.now() - delta)
128+
)
124129

125130
projects_finished = set()
126131
builds_finished = []

0 commit comments

Comments
 (0)