Skip to content

Commit adfa2af

Browse files
committed
Managers used in all the places
1 parent 54ef2b2 commit adfa2af

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

readthedocs/api/v3/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class BuildsViewSet(APIv3Settings, NestedViewSetMixin, ProjectQuerySetMixin,
269269
lookup_url_kwarg = 'build_pk'
270270
serializer_class = BuildSerializer
271271
filterset_class = BuildFilter
272-
queryset = Build.objects.all()
272+
queryset = Build.internal.all()
273273
permit_list_expands = [
274274
'config',
275275
]

readthedocs/builds/models.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def config(self):
207207
:rtype: dict
208208
"""
209209
last_build = (
210-
self.builds.filter(
210+
self.builds(manager=INTERNAL).filter(
211211
state='finished',
212212
success=True,
213213
).order_by('-date').first()
@@ -662,7 +662,7 @@ def previous(self):
662662
date = self.date or timezone.now()
663663
if self.project is not None and self.version is not None:
664664
return (
665-
Build.objects.filter(
665+
Build.internal.filter(
666666
project=self.project,
667667
version=self.version,
668668
date__lt=date,

readthedocs/builds/views.py

+15
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ def post(self, request, project_slug):
8484

8585
class BuildList(BuildBase, BuildTriggerMixin, ListView):
8686

87+
def get_queryset(self):
88+
# this is used to include only internal version
89+
# builds in the build list page
90+
self.project_slug = self.kwargs.get('project_slug', None)
91+
self.project = get_object_or_404(
92+
Project.objects.protected(self.request.user),
93+
slug=self.project_slug,
94+
)
95+
queryset = Build.internal.public(
96+
user=self.request.user,
97+
project=self.project,
98+
).select_related('project', 'version')
99+
100+
return queryset
101+
87102
def get_context_data(self, **kwargs):
88103
context = super().get_context_data(**kwargs)
89104

readthedocs/core/templatetags/privacy_tags.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_public_projects(context, user):
2626
viewer=context['request'].user,
2727
).prefetch_latest_build().annotate(
2828
_good_build=Exists(
29-
Build.objects.filter(success=True, project=OuterRef('pk')))
29+
Build.internal.filter(success=True, project=OuterRef('pk')))
3030
)
3131
context['public_projects'] = projects
3232
return ''

readthedocs/projects/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def has_good_build(self):
768768
# Used for Database optimization.
769769
if hasattr(self, '_good_build'):
770770
return self._good_build
771-
return self.builds.filter(success=True).exists()
771+
return self.builds(manager=INTERNAL).filter(success=True).exists()
772772

773773
@property
774774
def has_versions(self):

readthedocs/projects/querysets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ def prefetch_latest_build(self):
8585

8686
# Prefetch the latest build for each project.
8787
subquery = Subquery(
88-
Build.objects.filter(
88+
Build.internal.filter(
8989
project=OuterRef('project_id')
9090
).order_by('-date').values_list('id', flat=True)[:1]
9191
)
9292
latest_build = Prefetch(
9393
'builds',
94-
Build.objects.filter(pk__in=subquery),
94+
Build.internal.filter(pk__in=subquery),
9595
to_attr=self.model.LATEST_BUILD_CACHE,
9696
)
9797
return self.prefetch_related(latest_build)

0 commit comments

Comments
 (0)