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

Support for empty search3 queries

We already did (at least with SQLite), make sure it's the case (ie: test it)
and prevent useless WHERE when querying the database
This commit is contained in:
Alban Féron 2024-06-01 18:02:32 +02:00
parent 1271b30d64
commit 88997d5984
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
2 changed files with 14 additions and 3 deletions

View File

@ -200,9 +200,14 @@ def search_id3():
song_offset = int(song_offset) if song_offset else 0
root = get_root_folder(mfid)
artists = Artist.select().where(Artist.name.contains(query))
albums = Album.select().where(Album.name.contains(query))
songs = Track.select().where(Track.title.contains(query))
artists = Artist.select()
albums = Album.select()
songs = Track.select()
if query:
artists = artists.where(Artist.name.contains(query))
albums = albums.where(Album.name.contains(query))
songs = songs.where(Track.title.contains(query))
if root is not None:
artists = artists.join(Track).where(Track.root_folder == root)

View File

@ -420,6 +420,12 @@ class SearchTestCase(ApiTestBase):
)
self.assertEqual(len(self._xpath(child, "./song")), 0)
# empty query
rv, child = self._make_request("search3", {"query": ""}, tag="searchResult3")
self.assertEqual(len(child), 27) # 3 + 3*2 + 3*2*3
self.assertEqual(len(self._xpath(child, "./artist")), 3)
self.assertEqual(len(self._xpath(child, "./album")), 6)
self.assertEqual(len(self._xpath(child, "./song")), 18)
if __name__ == "__main__":
unittest.main()