Fixed some bugs with server search
This commit is contained in:
@@ -94,6 +94,9 @@ class SearchResult:
|
|||||||
self.query = query
|
self.query = query
|
||||||
|
|
||||||
def add_results(self, result_type, results):
|
def add_results(self, result_type, results):
|
||||||
|
if results is None:
|
||||||
|
return
|
||||||
|
|
||||||
member = f'_{result_type}'
|
member = f'_{result_type}'
|
||||||
if getattr(self, member) is None:
|
if getattr(self, member) is None:
|
||||||
setattr(self, member, set())
|
setattr(self, member, set())
|
||||||
@@ -894,12 +897,17 @@ class CacheManager(metaclass=Singleton):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Server search function
|
# Server search function
|
||||||
server_search = (
|
def server_search():
|
||||||
|
search_fn = (
|
||||||
self.server.search3
|
self.server.search3
|
||||||
if self.browse_by_tags else self.server.search2)
|
if self.browse_by_tags else self.server.search2)
|
||||||
|
result = search_fn(query)
|
||||||
|
yield ('album', result.album)
|
||||||
|
yield ('artist', result.artist)
|
||||||
|
yield ('song', result.song)
|
||||||
|
|
||||||
def playlist_search(_):
|
def playlist_search():
|
||||||
return ('playlist', CacheManager.get_playlists().result())
|
yield ('playlist', CacheManager.get_playlists().result())
|
||||||
|
|
||||||
before_download()
|
before_download()
|
||||||
|
|
||||||
@@ -910,16 +918,10 @@ class CacheManager(metaclass=Singleton):
|
|||||||
]
|
]
|
||||||
search_result = SearchResult(query)
|
search_result = SearchResult(query)
|
||||||
|
|
||||||
for i, f in enumerate(as_completed(
|
for i, f in enumerate(as_completed(map(
|
||||||
CacheManager.create_future(lambda: fn(query))
|
CacheManager.create_future, search_future_fns))):
|
||||||
for fn in search_future_fns)):
|
for member, result in f.result():
|
||||||
result = f.result()
|
search_result.add_results(member, result)
|
||||||
if isinstance(result, (SearchResult2, SearchResult3)):
|
|
||||||
search_result.add_results('album', result.album)
|
|
||||||
search_result.add_results('artist', result.artist)
|
|
||||||
search_result.add_results('song', result.song)
|
|
||||||
elif isinstance(result, tuple):
|
|
||||||
search_result.add_results(*result)
|
|
||||||
|
|
||||||
search_callback(
|
search_callback(
|
||||||
search_result,
|
search_result,
|
||||||
|
@@ -295,7 +295,6 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||||||
# If all results are back, the stop the loading indicator.
|
# If all results are back, the stop the loading indicator.
|
||||||
if is_last_in_batch:
|
if is_last_in_batch:
|
||||||
self.set_search_loading(False)
|
self.set_search_loading(False)
|
||||||
|
|
||||||
self.latest_returned_search_idx = idx
|
self.latest_returned_search_idx = idx
|
||||||
|
|
||||||
self.update_search_results(result)
|
self.update_search_results(result)
|
||||||
|
Reference in New Issue
Block a user