From: Marcel van der Veldt Date: Tue, 7 Jan 2025 23:37:17 +0000 (+0100) Subject: temp fix to reduce api calls by increasing sync interval drastically X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=a13f53155a93cd5ab36f23907e214f9032e04bd3;p=music-assistant-server.git temp fix to reduce api calls by increasing sync interval drastically Another bandaid in order to reduce the amount of calls to music providers. - increase default sync interval to 12 hours - don't always run sync at startup --- diff --git a/music_assistant/controllers/config.py b/music_assistant/controllers/config.py index f505cb63..6cefe509 100644 --- a/music_assistant/controllers/config.py +++ b/music_assistant/controllers/config.py @@ -916,4 +916,7 @@ class ConfigController: # loading failed, remove config self.remove(conf_key) raise + if prov.type == ProviderType.MUSIC: + # kick off initial library scan + self.mass.music.start_sync(None, [config.instance_id]) return config diff --git a/music_assistant/controllers/music.py b/music_assistant/controllers/music.py index 1a5f6ec7..d33ac4c7 100644 --- a/music_assistant/controllers/music.py +++ b/music_assistant/controllers/music.py @@ -34,7 +34,7 @@ from music_assistant_models.media_items import ( MediaItemType, SearchResults, ) -from music_assistant_models.provider import ProviderInstance, SyncTask +from music_assistant_models.provider import SyncTask from music_assistant.constants import ( DB_TABLE_ALBUM_ARTISTS, @@ -75,7 +75,7 @@ if TYPE_CHECKING: from music_assistant.models.music_provider import MusicProvider CONF_RESET_DB = "reset_db" -DEFAULT_SYNC_INTERVAL = 3 * 60 # default sync interval in minutes +DEFAULT_SYNC_INTERVAL = 12 * 60 # default sync interval in minutes CONF_SYNC_INTERVAL = "sync_interval" CONF_DELETED_PROVIDERS = "deleted_providers" CONF_ADD_LIBRARY_ON_PLAY = "add_library_on_play" @@ -894,7 +894,7 @@ class MusicController(CoreController): return instances def _start_provider_sync( - self, provider: ProviderInstance, media_types: tuple[MediaType, ...] + self, provider: MusicProvider, media_types: tuple[MediaType, ...] ) -> None: """Start sync task on provider and track progress.""" # check if we're not already running a sync task for this provider/mediatype @@ -1045,11 +1045,16 @@ class MusicController(CoreController): def _schedule_sync(self) -> None: """Schedule the periodic sync.""" - self.start_sync() - sync_interval = self.config.get_value(CONF_SYNC_INTERVAL) - # we reschedule ourselves right after execution - # NOTE: sync_interval is stored in minutes, we need seconds - self.mass.loop.call_later(sync_interval * 60, self._schedule_sync) + sync_interval = self.config.get_value(CONF_SYNC_INTERVAL) * 60 + + def run_scheduled_sync() -> None: + # kickoff the sync job + self.start_sync() + # reschedule ourselves + self.mass.loop.call_later(sync_interval, self._schedule_sync) + + # schedule the first sync run + self.mass.loop.call_later(sync_interval, run_scheduled_sync) async def _cleanup_database(self) -> None: """Perform database cleanup/maintenance.""" diff --git a/music_assistant/models/music_provider.py b/music_assistant/models/music_provider.py index 8bb08853..445a754a 100644 --- a/music_assistant/models/music_provider.py +++ b/music_assistant/models/music_provider.py @@ -63,7 +63,6 @@ class MusicProvider(Provider): async def loaded_in_mass(self) -> None: """Call after the provider has been loaded.""" - self.mass.music.start_sync(providers=[self.instance_id]) async def search( self,