From 79a8fa5915407c311b7fe8d17ecc3ac42e0dc5c0 Mon Sep 17 00:00:00 2001 From: Ciaran Ainsworth Date: Tue, 4 May 2021 16:07:27 +0100 Subject: [PATCH 1/4] Fixed vue widget and artist serializer --- api/funkwhale_api/music/serializers.py | 26 ++++++++++----------- front/src/components/audio/track/Widget.vue | 2 ++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/api/funkwhale_api/music/serializers.py b/api/funkwhale_api/music/serializers.py index 6e2c0fe2c..fb28fe6b8 100644 --- a/api/funkwhale_api/music/serializers.py +++ b/api/funkwhale_api/music/serializers.py @@ -161,20 +161,20 @@ def serialize_artist_simple(artist): "is_local": artist.is_local, "content_category": artist.content_category, } - if "description" in artist._state.fields_cache: - data["description"] = ( - common_serializers.ContentSerializer(artist.description).data - if artist.description - else None - ) - if "attachment_cover" in artist._state.fields_cache: - data["cover"] = ( - cover_field.to_representation(artist.attachment_cover) - if artist.attachment_cover - else None - ) - if "channel" in artist._state.fields_cache and artist.get_channel(): + data["description"] = ( + common_serializers.ContentSerializer(artist.description).data + if artist.description + else None + ) + + data["cover"] = ( + cover_field.to_representation(artist.attachment_cover) + if artist.attachment_cover + else None + ) + + if artist.get_channel(): data["channel"] = str(artist.channel.uuid) if getattr(artist, "_tracks_count", None) is not None: diff --git a/front/src/components/audio/track/Widget.vue b/front/src/components/audio/track/Widget.vue index 4092d054d..68d6988a9 100644 --- a/front/src/components/audio/track/Widget.vue +++ b/front/src/components/audio/track/Widget.vue @@ -8,6 +8,8 @@
+ +
-- GitLab From d1ad391c533aebdf8a91afa73a2aa4f5be84f6ba Mon Sep 17 00:00:00 2001 From: Ciaran Ainsworth Date: Sun, 9 May 2021 19:04:39 +0100 Subject: [PATCH 2/4] Add prefetched covers to history view --- api/funkwhale_api/history/views.py | 2 +- api/funkwhale_api/music/serializers.py | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/api/funkwhale_api/history/views.py b/api/funkwhale_api/history/views.py index a14917fc1..b08bbdbd3 100644 --- a/api/funkwhale_api/history/views.py +++ b/api/funkwhale_api/history/views.py @@ -56,7 +56,7 @@ class ListeningViewSet( ) tracks = Track.objects.with_playable_uploads( music_utils.get_actor_from_request(self.request) - ).select_related("artist", "album__artist", "attributed_to") + ).select_related("artist", "album__artist", "attributed_to", "artist__attachment_cover") return queryset.prefetch_related(Prefetch("track", queryset=tracks)) def get_serializer_context(self): diff --git a/api/funkwhale_api/music/serializers.py b/api/funkwhale_api/music/serializers.py index fb28fe6b8..fcf4a4bf2 100644 --- a/api/funkwhale_api/music/serializers.py +++ b/api/funkwhale_api/music/serializers.py @@ -162,17 +162,19 @@ def serialize_artist_simple(artist): "content_category": artist.content_category, } - data["description"] = ( - common_serializers.ContentSerializer(artist.description).data - if artist.description - else None - ) + if "description" in artist._state.fields_cache: + data["description"] = ( + common_serializers.ContentSerializer(artist.description).data + if artist.description + else None + ) - data["cover"] = ( - cover_field.to_representation(artist.attachment_cover) - if artist.attachment_cover - else None - ) + if "attachment_cover" in artist._state.fields_cache: + data["cover"] = ( + cover_field.to_representation(artist.attachment_cover) + if artist.attachment_cover + else None + ) if artist.get_channel(): data["channel"] = str(artist.channel.uuid) -- GitLab From 896f648abe40cef343eb0596a110b30632a53fc6 Mon Sep 17 00:00:00 2001 From: Ciaran Ainsworth Date: Sun, 9 May 2021 19:06:46 +0100 Subject: [PATCH 3/4] Undo changes to serializer --- api/funkwhale_api/music/serializers.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/funkwhale_api/music/serializers.py b/api/funkwhale_api/music/serializers.py index fcf4a4bf2..6e2c0fe2c 100644 --- a/api/funkwhale_api/music/serializers.py +++ b/api/funkwhale_api/music/serializers.py @@ -161,7 +161,6 @@ def serialize_artist_simple(artist): "is_local": artist.is_local, "content_category": artist.content_category, } - if "description" in artist._state.fields_cache: data["description"] = ( common_serializers.ContentSerializer(artist.description).data @@ -175,8 +174,7 @@ def serialize_artist_simple(artist): if artist.attachment_cover else None ) - - if artist.get_channel(): + if "channel" in artist._state.fields_cache and artist.get_channel(): data["channel"] = str(artist.channel.uuid) if getattr(artist, "_tracks_count", None) is not None: -- GitLab From cec91ec2036da91cd90707f4ed30b7598807c8dc Mon Sep 17 00:00:00 2001 From: Ciaran Ainsworth Date: Sun, 9 May 2021 19:09:11 +0100 Subject: [PATCH 4/4] Fix linting issue --- api/funkwhale_api/history/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/funkwhale_api/history/views.py b/api/funkwhale_api/history/views.py index b08bbdbd3..0a7992756 100644 --- a/api/funkwhale_api/history/views.py +++ b/api/funkwhale_api/history/views.py @@ -56,7 +56,9 @@ class ListeningViewSet( ) tracks = Track.objects.with_playable_uploads( music_utils.get_actor_from_request(self.request) - ).select_related("artist", "album__artist", "attributed_to", "artist__attachment_cover") + ).select_related( + "artist", "album__artist", "attributed_to", "artist__attachment_cover" + ) return queryset.prefetch_related(Prefetch("track", queryset=tracks)) def get_serializer_context(self): -- GitLab