Skip to content

Commit

Permalink
Merge pull request #96 from snypy/optimize-list-performance
Browse files Browse the repository at this point in the history
Add snippet list prefetch options
  • Loading branch information
nezhar authored Aug 27, 2022
2 parents e180a61 + bda2999 commit baeec4b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions snypy/snippets/rest/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ def get_permissions(self):
]
return super().get_permissions()

def get_queryset(self):
"""
Extend default queryset to improve performance
"""
return (
self.queryset.viewable()
.select_related(
"user",
"team",
)
.prefetch_related(
"files",
"labels",
)
)


class FileViewSet(BaseModelViewSet):
queryset = File.objects.all()
Expand Down

0 comments on commit baeec4b

Please sign in to comment.