1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Fix getSongsByGenre + remove some useless DISTINCTs

This commit is contained in:
Alban Féron 2023-01-02 18:08:30 +01:00
parent 09d48fdb2e
commit 30734fe9ab
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
2 changed files with 25 additions and 5 deletions

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2013-2022 Alban 'spl0k' Féron # Copyright (C) 2013-2023 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -84,7 +84,7 @@ def album_list():
}, },
) )
elif ltype == "newest": elif ltype == "newest":
query = query.order_by(Folder.created.desc()).distinct() query = query.order_by(Folder.created.desc())
elif ltype == "highest": elif ltype == "highest":
query = query.join(RatingFolder, JOIN.LEFT_OUTER).order_by( query = query.join(RatingFolder, JOIN.LEFT_OUTER).order_by(
fn.avg(RatingFolder.rating).desc() fn.avg(RatingFolder.rating).desc()
@ -98,7 +98,7 @@ def album_list():
elif ltype == "starred": elif ltype == "starred":
query = query.join(StarredFolder).where(StarredFolder.user == request.user) query = query.join(StarredFolder).where(StarredFolder.user == request.user)
elif ltype == "alphabeticalByName": elif ltype == "alphabeticalByName":
query = query.order_by(Folder.name).distinct() query = query.order_by(Folder.name)
elif ltype == "alphabeticalByArtist": elif ltype == "alphabeticalByArtist":
parent = Folder.alias() parent = Folder.alias()
query = query.join(parent).order_by(parent.name, Folder.name) query = query.join(parent).order_by(parent.name, Folder.name)
@ -212,7 +212,7 @@ def songs_by_genre():
{ {
"song": [ "song": [
t.as_subsonic_child(request.user, request.client) t.as_subsonic_child(request.user, request.client)
for t in query.limit(count, offset) for t in query.limit(count).offset(offset)
] ]
}, },
) )

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2017-2022 Alban 'spl0k' Féron # Copyright (C) 2017-2023 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -267,6 +267,26 @@ class AlbumSongsTestCase(ApiTestBase):
self._make_request("getStarred2", tag="starred2") self._make_request("getStarred2", tag="starred2")
self._make_request("getStarred2", {"musicFolderId": 1}, tag="starred2") self._make_request("getStarred2", {"musicFolderId": 1}, tag="starred2")
def test_get_songs_by_genre(self):
self._make_request("getSongsByGenre", error=10)
self._make_request(
"getSongsByGenre", {"genre": "genre", "musicFolderId": "idid"}, error=0
)
self._make_request(
"getSongsByGenre", {"genre": "genre", "musicFolderId": 1234567890}, error=70
)
self._make_request(
"getSongsByGenre", {"genre": "genre", "count": "three"}, error=0
)
self._make_request(
"getSongsByGenre", {"genre": "genre", "offset": "four"}, error=0
)
rv, child = self._make_request(
"getSongsByGenre", {"genre": "Lampshade"}, tag="songsByGenre"
)
self.assertEqual(len(child), 1)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()