Skip to content

Commit fdf1f2c

Browse files
committed
Revert "Prefetch build and project on version list (#11616)"
This reverts commit e5f8092.
1 parent f8cbc13 commit fdf1f2c

File tree

3 files changed

+2
-46
lines changed

3 files changed

+2
-46
lines changed

readthedocs/builds/models.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ class Meta:
207207
unique_together = [("project", "slug")]
208208
ordering = ["-verbose_name"]
209209

210-
# Property used for prefetching version related fields
211-
LATEST_BUILD_CACHE = "_latest_build"
212-
213210
def __str__(self):
214211
return self.verbose_name
215212

@@ -294,19 +291,6 @@ def vcs_url(self):
294291

295292
@property
296293
def last_build(self):
297-
# TODO deprecated in favor of `latest_build`, which matches naming on
298-
# the Project model
299-
return self.latest_build
300-
301-
@property
302-
def latest_build(self):
303-
# Check if there is `_latest_build` prefetch in the Queryset.
304-
# Used for database optimization.
305-
if hasattr(self, self.LATEST_BUILD_CACHE):
306-
if latest_build := getattr(self, self.LATEST_BUILD_CACHE):
307-
return latest_build[0]
308-
return None
309-
310294
return self.builds.order_by("-date").first()
311295

312296
@property

readthedocs/builds/querysets.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import structlog
55
from django.db import models
6-
from django.db.models import OuterRef, Prefetch, Q, Subquery
6+
from django.db.models import Q
77
from django.utils import timezone
88

99
from readthedocs.builds.constants import (
@@ -141,30 +141,6 @@ def for_reindex(self):
141141
.distinct()
142142
)
143143

144-
def prefetch_subquery(self):
145-
"""
146-
Prefetch related objects via subquery for each version.
147-
148-
.. note::
149-
150-
This should come after any filtering.
151-
"""
152-
from readthedocs.builds.models import Build
153-
154-
# Prefetch the latest build for each project.
155-
subquery_builds = Subquery(
156-
Build.internal.filter(version=OuterRef("version_id"))
157-
.order_by("-date")
158-
.values_list("id", flat=True)[:1]
159-
)
160-
prefetch_builds = Prefetch(
161-
"builds",
162-
Build.internal.filter(pk__in=subquery_builds),
163-
to_attr=self.model.LATEST_BUILD_CACHE,
164-
)
165-
166-
return self.prefetch_related(prefetch_builds)
167-
168144

169145
class VersionQuerySet(SettingsOverrideObject):
170146
_default_class = VersionQuerySetBase

readthedocs/projects/views/public.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,7 @@ def get_context_data(self, **kwargs):
123123
queryset=versions,
124124
project=project,
125125
)
126-
versions = (
127-
self.get_filtered_queryset()
128-
.prefetch_related("project")
129-
.prefetch_subquery()
130-
)
126+
versions = self.get_filtered_queryset()
131127
context["versions"] = versions
132128

133129
protocol = "http"

0 commit comments

Comments
 (0)