Skip to content

Commit

Permalink
Support for empty search3 queries
Browse files Browse the repository at this point in the history
We already did (at least with SQLite), make sure it's the case (ie: test it)
and prevent useless WHERE when querying the database
  • Loading branch information
spl0k committed Jun 1, 2024
1 parent 1271b30 commit 88997d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions supysonic/api/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/api/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ def test_search3(self):
)
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()

0 comments on commit 88997d5

Please sign in to comment.