Skip to content

Commit d5f5e07

Browse files
authored
Add Project queryset prefetch_latest_build() to project filter (#12225)
This was missing from the queryset, causing the templates to use `Project.get_latest_build(finished=True)`, effectively. When using `prefetch_latest_build()`, the response from `get_latest_build` is the first build of _any_ build state. - Refs readthedocs/ext-theme#607 - Refs #11840
1 parent 1d50bb7 commit d5f5e07

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

readthedocs/projects/filters.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ def filter(self, qs, value):
138138
else:
139139
order_bys.append(field_ordered)
140140

141-
return qs.annotate(**annotations).order_by(*order_bys)
141+
# Prefetch here not only prefetches the query, but it also changes how `get_latest_build`
142+
# works. Normally from templates `project.get_latest_build` only returns
143+
# the latest _finished_ build. But with prefetch, _all_ builds are
144+
# considered and `get_latest_build` will pop the first off this list of
145+
# _all_ builds.
146+
return qs.prefetch_latest_build().annotate(**annotations).order_by(*order_bys)
142147

143148

144149
class ProjectListFilterSet(ModelFilterSet):

0 commit comments

Comments
 (0)