Skip to content

Commit 57a27dd

Browse files
committed
Prefetch relations on Project queryset
1 parent 80c0ed1 commit 57a27dd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

readthedocs/api/v3/views.py

+11
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ class ProjectsViewSet(APIv3Settings, APIAuthMixin, NestedViewSetMixin,
132132
'active_versions.last_build.config',
133133
]
134134

135+
def get_queryset(self):
136+
# This could be a class attribute and managed on the ``APIAuthMixin`` in
137+
# case we want to extend the ``prefetch_related`` to other views as
138+
# well.
139+
queryset = super().get_queryset()
140+
return queryset.prefetch_related(
141+
'related_projects',
142+
'domains',
143+
'tags',
144+
)
145+
135146
def get_view_description(self, *args, **kwargs):
136147
"""
137148
Make valid links for the user's documentation browseable API.

0 commit comments

Comments
 (0)