Fixed really slow SQL
This commit is contained in:
parent
8b0ce6ad33
commit
1295144681
6 changed files with 19 additions and 12 deletions
|
|
@ -152,8 +152,10 @@ class ArtistViewSet(
|
|||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
albums = models.Album.objects.with_tracks_count().select_related(
|
||||
"attachment_cover"
|
||||
albums = (
|
||||
models.Album.objects.with_tracks_count()
|
||||
.select_related("attachment_cover")
|
||||
.prefetch_related("tracks")
|
||||
)
|
||||
albums = albums.annotate_playable_by_actor(
|
||||
utils.get_actor_from_request(self.request)
|
||||
|
|
@ -179,10 +181,10 @@ class AlbumViewSet(
|
|||
viewsets.ReadOnlyModelViewSet,
|
||||
):
|
||||
queryset = (
|
||||
models.Album.objects.all()
|
||||
.order_by("-creation_date")
|
||||
.with_tracks_count()
|
||||
.prefetch_related("artist", "attributed_to", "attachment_cover")
|
||||
models.Album.objects.all().order_by("-creation_date")
|
||||
# we do a prefetech related on tracks instead of a count because it's more efficient
|
||||
# db-wise
|
||||
.prefetch_related("artist", "attributed_to", "attachment_cover", "tracks")
|
||||
)
|
||||
serializer_class = serializers.AlbumSerializer
|
||||
permission_classes = [oauth_permissions.ScopePermission]
|
||||
|
|
@ -759,7 +761,7 @@ class Search(views.APIView):
|
|||
"album",
|
||||
queryset=models.Album.objects.select_related(
|
||||
"artist", "attachment_cover", "attributed_to"
|
||||
),
|
||||
).prefetch_related("tracks"),
|
||||
),
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue