From cb3f9023a54a7591a5f8d240156c3cad597e0c30 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Tue, 12 Mar 2024 20:29:14 +0100 Subject: [PATCH] speed-up config retrievals --- music_assistant/server/controllers/config.py | 17 +++++++++++++---- music_assistant/server/controllers/players.py | 2 +- .../server/providers/ugp/__init__.py | 4 +++- music_assistant/server/server.py | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/music_assistant/server/controllers/config.py b/music_assistant/server/controllers/config.py index c0331a8a2..c6c99bd74 100644 --- a/music_assistant/server/controllers/config.py +++ b/music_assistant/server/controllers/config.py @@ -160,12 +160,15 @@ async def get_provider_configs( self, provider_type: ProviderType | None = None, provider_domain: str | None = None, + include_values: bool = False, ) -> list[ProviderConfig]: """Return all known provider configurations, optionally filtered by ProviderType.""" raw_values: dict[str, dict] = self.get(CONF_PROVIDERS, {}) prov_entries = {x.domain for x in self.mass.get_provider_manifests()} return [ await self.get_provider_config(prov_conf["instance_id"]) + if include_values + else ProviderConfig.parse([], prov_conf) for prov_conf in raw_values.values() if (provider_type is None or prov_conf["type"] == provider_type) and (provider_domain is None or prov_conf["domain"] == provider_domain) @@ -317,11 +320,15 @@ async def reload_provider(self, instance_id: str) -> None: await self._load_provider_config(config) @api_command("config/players") - async def get_player_configs(self, provider: str | None = None) -> list[PlayerConfig]: + async def get_player_configs( + self, provider: str | None = None, include_values: bool = False + ) -> list[PlayerConfig]: """Return all known player configurations, optionally filtered by provider domain.""" available_providers = {x.instance_id for x in self.mass.providers} return [ await self.get_player_config(raw_conf["player_id"]) + if include_values + else PlayerConfig.parse([], raw_conf) for raw_conf in list(self.get(CONF_PLAYERS, {}).values()) # filter out unavailable providers if raw_conf["provider"] in available_providers @@ -501,12 +508,14 @@ async def create_default_provider_config(self, provider_domain: str) -> None: self.set(conf_key, default_config.to_raw()) @api_command("config/core") - async def get_core_configs( - self, - ) -> list[CoreConfig]: + async def get_core_configs(self, include_values: bool = False) -> list[CoreConfig]: """Return all core controllers config options.""" return [ await self.get_core_config(core_controller) + if include_values + else CoreConfig.parse( + [], self.get(f"{CONF_CORE}/{core_controller}", {"domain": core_controller}) + ) for core_controller in CONFIGURABLE_CORE_CONTROLLERS ] diff --git a/music_assistant/server/controllers/players.py b/music_assistant/server/controllers/players.py index 58171ae66..3702c3775 100644 --- a/music_assistant/server/controllers/players.py +++ b/music_assistant/server/controllers/players.py @@ -953,7 +953,7 @@ async def _sync_syncgroup(self, player_id: str) -> None: async def _register_syncgroups(self) -> None: """Register all (virtual/fake) syncgroup players.""" - player_configs = await self.mass.config.get_player_configs() + player_configs = await self.mass.config.get_player_configs(include_values=True) for player_config in player_configs: if not player_config.player_id.startswith(SYNCGROUP_PREFIX): continue diff --git a/music_assistant/server/providers/ugp/__init__.py b/music_assistant/server/providers/ugp/__init__.py index a86c76608..51ee24d73 100644 --- a/music_assistant/server/providers/ugp/__init__.py +++ b/music_assistant/server/providers/ugp/__init__.py @@ -228,7 +228,9 @@ async def create_group(self, name: str, members: list[str]) -> Player: async def _register_all_players(self) -> None: """Register all (virtual/fake) group players in the Player controller.""" - player_configs = await self.mass.config.get_player_configs(self.instance_id) + player_configs = await self.mass.config.get_player_configs( + self.instance_id, include_values=True + ) for player_config in player_configs: members = player_config.get_value(CONF_GROUP_MEMBERS) self._register_group_player( diff --git a/music_assistant/server/server.py b/music_assistant/server/server.py index 65d92921e..9a2f2dc7e 100644 --- a/music_assistant/server/server.py +++ b/music_assistant/server/server.py @@ -515,7 +515,7 @@ async def load_provider(prov_conf: ProviderConfig) -> None: self.config.set(f"{CONF_PROVIDERS}/{prov_conf.instance_id}/last_error", str(exc)) # load all configured (and enabled) providers - prov_configs = await self.config.get_provider_configs() + prov_configs = await self.config.get_provider_configs(include_values=True) async with asyncio.TaskGroup() as tg: for prov_conf in prov_configs: if not prov_conf.enabled: