"""Message sent when a Command has been successfully executed."""
result: Any = field(default=None, metadata={"serialize": lambda v: get_serializable_value(v)})
+ partial: bool = False
@dataclass
extra_query_params: dict[str, Any] = extra_query_params or {}
extra_query_parts: list[str] = [extra_query] if extra_query else []
extra_join_parts: list[str] = []
+ artist_table_joined = False
# optional album type filter
if album_types:
extra_query_parts.append("albums.album_type IN :album_types")
"sort_name": update.sort_name
if overwrite
else cur_item.sort_name or update.sort_name,
- "version": update.version if overwrite else cur_item.version,
+ "version": update.version if overwrite else cur_item.version or update.version,
"year": update.year if overwrite else cur_item.year or update.year,
"album_type": album_type.value,
"metadata": serialize_to_json(metadata),
ItemMapping,
MediaItemType,
ProviderMapping,
+ SearchResults,
Track,
- media_from_dict,
)
from music_assistant.constants import DB_TABLE_PLAYLOG, DB_TABLE_PROVIDER_MAPPINGS, MASS_LOGGER_NAME
from music_assistant.server.helpers.compare import compare_media_item
cache_key, category=cache_category, base_key=cache_base_key
)
) is not None:
- return [media_from_dict(x) for x in cache]
- # no items in cache - get listing from provider
- searchresult = await prov.search(
- search_query,
- [self.media_type],
- limit,
- )
+ searchresult = SearchResults.from_dict(cache)
+ else:
+ # no items in cache - get listing from provider
+ searchresult = await prov.search(
+ search_query,
+ [self.media_type],
+ limit,
+ )
if self.media_type == MediaType.ARTIST:
items = searchresult.artists
elif self.media_type == MediaType.ALBUM:
self.mass.create_task(
self.mass.cache.set(
cache_key,
- [x.to_dict() for x in items],
+ searchresult.to_dict(),
expiration=86400 * 7,
category=cache_category,
base_key=cache_base_key,
)
album.metadata.update(prov_item.metadata)
if album.year is None and prov_item.year:
- album.year = prov_item
+ album.year = prov_item.year
if album.album_type == AlbumType.UNKNOWN:
album.album_type = prov_item.album_type
from concurrent import futures
from contextlib import suppress
from functools import partial
-from typing import TYPE_CHECKING, Final
+from typing import TYPE_CHECKING, Any, Final
from aiohttp import WSMsgType, web
from music_assistant_frontend import where as locate_frontend
args = parse_arguments(handler.signature, handler.type_hints, msg.args)
result = handler.target(**args)
if hasattr(result, "__anext__"):
- # handle async generator
- result = [x async for x in result]
+ # handle async generator (for really large listings)
+ iterator = result
+ result: list[Any] = []
+ async for item in iterator:
+ result.append(item)
+ if len(result) >= 500:
+ self._send_message(
+ SuccessResultMessage(msg.message_id, result, partial=True)
+ )
+ result = []
elif asyncio.iscoroutine(result):
result = await result
self._send_message(SuccessResultMessage(msg.message_id, result))