File tree 2 files changed +4
-28
lines changed 2 files changed +4
-28
lines changed Original file line number Diff line number Diff line change @@ -575,7 +575,6 @@ class Project(models.Model):
575
575
576
576
# Property used for storing the latest build for a project when prefetching
577
577
LATEST_BUILD_CACHE = "_latest_build"
578
- LATEST_SUCCESSFUL_BUILD_CACHE = "_latest_successful_build"
579
578
580
579
class Meta :
581
580
ordering = ("slug" ,)
@@ -921,13 +920,6 @@ def conf_dir(self, version=LATEST):
921
920
922
921
@property
923
922
def has_good_build (self ):
924
- # Check if there is `_latest_successful_build` attribute in the Queryset.
925
- # Used for database optimization.
926
- if hasattr (self , self .LATEST_SUCCESSFUL_BUILD_CACHE ):
927
- if build_successful := getattr (self , self .LATEST_SUCCESSFUL_BUILD_CACHE ):
928
- return build_successful [0 ]
929
- return None
930
-
931
923
# Check if there is `_good_build` annotation in the Queryset.
932
924
# Used for Database optimization.
933
925
if hasattr (self , "_good_build" ):
Original file line number Diff line number Diff line change @@ -132,33 +132,17 @@ def prefetch_latest_build(self):
132
132
from readthedocs .builds .models import Build
133
133
134
134
# Prefetch the latest build for each project.
135
- subquery_build_latest = Subquery (
135
+ subquery = Subquery (
136
136
Build .internal .filter (project = OuterRef ("project_id" ))
137
137
.order_by ("-date" )
138
138
.values_list ("id" , flat = True )[:1 ]
139
139
)
140
- prefetch_build_latest = Prefetch (
140
+ latest_build = Prefetch (
141
141
"builds" ,
142
- Build .internal .filter (pk__in = subquery_build_latest ),
142
+ Build .internal .filter (pk__in = subquery ),
143
143
to_attr = self .model .LATEST_BUILD_CACHE ,
144
144
)
145
-
146
- # Prefetch the latest successful build for each project.
147
- subquery_build_successful = Subquery (
148
- Build .internal .filter (project = OuterRef ("project_id" ))
149
- .order_by ("-date" )
150
- .values_list ("id" , flat = True )[:1 ]
151
- )
152
- prefetch_build_successful = Prefetch (
153
- "builds" ,
154
- Build .internal .filter (pk__in = subquery_build_successful ),
155
- to_attr = self .model .LATEST_SUCCESSFUL_BUILD_CACHE ,
156
- )
157
-
158
- return self .prefetch_related (
159
- prefetch_build_latest ,
160
- prefetch_build_successful ,
161
- )
145
+ return self .prefetch_related (latest_build )
162
146
163
147
# Aliases
164
148
You can’t perform that action at this time.
0 commit comments