Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mélanie Chauvel
funkwhale
Commits
1ca7f62a
Verified
Commit
1ca7f62a
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Small performance enhancements
parent
5623b6d8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/funkwhale_api/music/models.py
+3
-2
3 additions, 2 deletions
api/funkwhale_api/music/models.py
api/funkwhale_api/music/serializers.py
+49
-79
49 additions, 79 deletions
api/funkwhale_api/music/serializers.py
with
52 additions
and
81 deletions
api/funkwhale_api/music/models.py
+
3
−
2
View file @
1ca7f62a
...
...
@@ -436,7 +436,7 @@ class TrackQuerySet(common_models.LocalFromFidQuerySet, models.QuerySet):
return
self
.
exclude
(
pk__in
=
matches
)
def
with_playable_uploads
(
self
,
actor
):
uploads
=
Upload
.
objects
.
playable_by
(
actor
)
.
select_related
(
"
track
"
)
uploads
=
Upload
.
objects
.
playable_by
(
actor
)
return
self
.
prefetch_related
(
models
.
Prefetch
(
"
uploads
"
,
queryset
=
uploads
,
to_attr
=
"
playable_uploads
"
)
)
...
...
@@ -594,7 +594,8 @@ class Track(APIModelMixin):
@property
def
listen_url
(
self
):
return
reverse
(
"
api:v1:listen-detail
"
,
kwargs
=
{
"
uuid
"
:
self
.
uuid
})
# Not using reverse because this is slow
return
"
/api/v1/listen/{}/
"
.
format
(
self
.
uuid
)
@property
def
local_license
(
self
):
...
...
This diff is collapsed.
Click to expand it.
api/funkwhale_api/music/serializers.py
+
49
−
79
View file @
1ca7f62a
...
...
@@ -45,26 +45,21 @@ class LicenseSerializer(serializers.Serializer):
return
obj
[
"
identifiers
"
][
0
]
class
ArtistAlbumSerializer
(
serializers
.
Model
Serializer
):
class
ArtistAlbumSerializer
(
serializers
.
Serializer
):
tracks_count
=
serializers
.
SerializerMethodField
()
cover
=
cover_field
is_playable
=
serializers
.
SerializerMethodField
()
is_local
=
serializers
.
BooleanField
()
id
=
serializers
.
IntegerField
()
fid
=
serializers
.
URLField
()
mbid
=
serializers
.
UUIDField
()
title
=
serializers
.
CharField
()
artist
=
serializers
.
SerializerMethodField
()
release_date
=
serializers
.
DateField
()
creation_date
=
serializers
.
DateTimeField
()
class
Meta
:
model
=
models
.
Album
fields
=
(
"
id
"
,
"
fid
"
,
"
mbid
"
,
"
title
"
,
"
artist
"
,
"
release_date
"
,
"
cover
"
,
"
creation_date
"
,
"
tracks_count
"
,
"
is_playable
"
,
"
is_local
"
,
)
def
get_artist
(
self
,
o
):
return
o
.
artist_id
def
get_tracks_count
(
self
,
o
):
return
o
.
_tracks_count
...
...
@@ -76,26 +71,20 @@ class ArtistAlbumSerializer(serializers.ModelSerializer):
return
None
class
ArtistWithAlbumsSerializer
(
serializers
.
ModelSerializer
):
albums
=
ArtistAlbumSerializer
(
many
=
True
,
read_only
=
True
)
DATETIME_FIELD
=
serializers
.
DateTimeField
()
class
ArtistWithAlbumsSerializer
(
serializers
.
Serializer
):
albums
=
ArtistAlbumSerializer
(
many
=
True
)
tags
=
serializers
.
SerializerMethodField
()
attributed_to
=
serializers
.
SerializerMethodField
()
tracks_count
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
models
.
Artist
fields
=
(
"
id
"
,
"
fid
"
,
"
mbid
"
,
"
name
"
,
"
creation_date
"
,
"
albums
"
,
"
is_local
"
,
"
tags
"
,
"
attributed_to
"
,
"
tracks_count
"
,
)
id
=
serializers
.
IntegerField
()
fid
=
serializers
.
URLField
()
mbid
=
serializers
.
UUIDField
()
name
=
serializers
.
CharField
()
creation_date
=
serializers
.
DateTimeField
()
is_local
=
serializers
.
BooleanField
()
def
get_tags
(
self
,
obj
):
tagged_items
=
getattr
(
obj
,
"
_prefetched_tagged_items
"
,
[])
...
...
@@ -114,9 +103,7 @@ def serialize_artist_simple(artist):
"
fid
"
:
artist
.
fid
,
"
mbid
"
:
str
(
artist
.
mbid
),
"
name
"
:
artist
.
name
,
"
creation_date
"
:
serializers
.
DateTimeField
().
to_representation
(
artist
.
creation_date
),
"
creation_date
"
:
DATETIME_FIELD
.
to_representation
(
artist
.
creation_date
),
"
is_local
"
:
artist
.
is_local
,
}
...
...
@@ -129,9 +116,7 @@ def serialize_album_track(track):
"
title
"
:
track
.
title
,
"
artist
"
:
serialize_artist_simple
(
track
.
artist
),
"
album
"
:
track
.
album_id
,
"
creation_date
"
:
serializers
.
DateTimeField
().
to_representation
(
track
.
creation_date
),
"
creation_date
"
:
DATETIME_FIELD
.
to_representation
(
track
.
creation_date
),
"
position
"
:
track
.
position
,
"
disc_number
"
:
track
.
disc_number
,
"
uploads
"
:
[
...
...
@@ -145,31 +130,22 @@ def serialize_album_track(track):
}
class
AlbumSerializer
(
serializers
.
Model
Serializer
):
class
AlbumSerializer
(
serializers
.
Serializer
):
tracks
=
serializers
.
SerializerMethodField
()
artist
=
serializers
.
SerializerMethodField
()
cover
=
cover_field
is_playable
=
serializers
.
SerializerMethodField
()
tags
=
serializers
.
SerializerMethodField
()
attributed_to
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
models
.
Album
fields
=
(
"
id
"
,
"
fid
"
,
"
mbid
"
,
"
title
"
,
"
artist
"
,
"
tracks
"
,
"
release_date
"
,
"
cover
"
,
"
creation_date
"
,
"
is_playable
"
,
"
is_local
"
,
"
tags
"
,
"
attributed_to
"
,
)
id
=
serializers
.
IntegerField
()
fid
=
serializers
.
URLField
()
mbid
=
serializers
.
UUIDField
()
title
=
serializers
.
CharField
()
artist
=
serializers
.
SerializerMethodField
()
release_date
=
serializers
.
DateField
()
creation_date
=
serializers
.
DateTimeField
()
is_local
=
serializers
.
BooleanField
()
is_playable
=
serializers
.
SerializerMethodField
()
get_attributed_to
=
serialize_attributed_to
...
...
@@ -227,7 +203,7 @@ def serialize_upload(upload):
}
class
TrackSerializer
(
serializers
.
Model
Serializer
):
class
TrackSerializer
(
serializers
.
Serializer
):
artist
=
serializers
.
SerializerMethodField
()
album
=
TrackAlbumSerializer
(
read_only
=
True
)
uploads
=
serializers
.
SerializerMethodField
()
...
...
@@ -235,26 +211,17 @@ class TrackSerializer(serializers.ModelSerializer):
tags
=
serializers
.
SerializerMethodField
()
attributed_to
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
models
.
Track
fields
=
(
"
id
"
,
"
fid
"
,
"
mbid
"
,
"
title
"
,
"
album
"
,
"
artist
"
,
"
creation_date
"
,
"
position
"
,
"
disc_number
"
,
"
uploads
"
,
"
listen_url
"
,
"
copyright
"
,
"
license
"
,
"
is_local
"
,
"
tags
"
,
"
attributed_to
"
,
)
id
=
serializers
.
IntegerField
()
fid
=
serializers
.
URLField
()
mbid
=
serializers
.
UUIDField
()
title
=
serializers
.
CharField
()
artist
=
serializers
.
SerializerMethodField
()
creation_date
=
serializers
.
DateTimeField
()
is_local
=
serializers
.
BooleanField
()
position
=
serializers
.
IntegerField
()
disc_number
=
serializers
.
IntegerField
()
copyright
=
serializers
.
CharField
()
license
=
serializers
.
SerializerMethodField
()
get_attributed_to
=
serialize_attributed_to
...
...
@@ -271,6 +238,9 @@ class TrackSerializer(serializers.ModelSerializer):
tagged_items
=
getattr
(
obj
,
"
_prefetched_tagged_items
"
,
[])
return
[
ti
.
tag
.
name
for
ti
in
tagged_items
]
def
get_license
(
self
,
o
):
return
o
.
license_id
@common_serializers.track_fields_for_update
(
"
name
"
,
"
description
"
,
"
privacy_level
"
)
class
LibraryForOwnerSerializer
(
serializers
.
ModelSerializer
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment