Skip to content

Commit

Permalink
fix: n+1 queries
Browse files Browse the repository at this point in the history
  • Loading branch information
alubbock committed Mar 12, 2024
1 parent ea13552 commit e2cd569
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions backend/antigenapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ class Meta: # noqa: D106
class LibraryViewSet(AuditLogMixin, DeleteProtectionMixin, ModelViewSet):
"""A view set for libraries."""

queryset = Library.objects.all().select_related("cohort").select_related("project")
queryset = (
Library.objects.all()
.select_related("cohort")
.select_related("project")
.select_related("added_by")
)
serializer_class = LibrarySerializer
filterset_fields = ("project",)

Expand Down Expand Up @@ -379,7 +384,11 @@ def update(self, instance, validated_data):
class ElisaPlateViewSet(AuditLogMixin, DeleteProtectionMixin, ModelViewSet):
"""A view set displaying all recorded elisa plates."""

queryset = ElisaPlate.objects.all().select_related("library__cohort")
queryset = (
ElisaPlate.objects.all()
.select_related("library__cohort")
.select_related("library__project")
)
serializer_class = ElisaPlateSerializer
filterset_fields = ("library", "library__cohort")

Expand Down

0 comments on commit e2cd569

Please sign in to comment.