Skip to content

Commit 17363eb

Browse files
Shi-553Shi-553
authored andcommitted
refactor: improve get_following_activities and fix throttler settings
- Call get_track directly instead of get_provider_item for simplicity - Remove unnecessary semaphore (throttler already handles rate limiting) - Fix throttler settings: rate_limit=5, period=1 (5 req/sec) for high priority - Fix low priority throttler: period=1 for consistency
1 parent 232f76f commit 17363eb

File tree

2 files changed

+3
-19
lines changed

2 files changed

+3
-19
lines changed

music_assistant/providers/nicovideo/services/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def __init__(self, provider: MusicProvider, nicovideo_config: NicovideoConfig) -
4747
self.mass = provider.mass
4848
self.reset_niconico_py_client()
4949

50-
self.niconico_api_throttler = ThrottlerManager(rate_limit=1, period=0)
50+
self.niconico_api_throttler = ThrottlerManager(rate_limit=5, period=1)
5151
# Low priority throttler for background tag updates (slower rate)
52-
self.niconico_api_throttler_low_priority = ThrottlerManager(rate_limit=1, period=0.3)
52+
self.niconico_api_throttler_low_priority = ThrottlerManager(rate_limit=1, period=1)
5353

5454
self.logger = provider.logger
5555

music_assistant/providers/nicovideo/services/user.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import asyncio
66
from typing import TYPE_CHECKING
77

8-
from music_assistant_models.errors import MediaNotFoundError
9-
108
from music_assistant.providers.nicovideo.constants import SENSITIVE_CONTENTS
119
from music_assistant.providers.nicovideo.services.base import NicovideoBaseService
1210

@@ -169,21 +167,7 @@ async def get_following_activities(self, limit: int = 50) -> list[Track]:
169167
if len(video_ids) >= limit:
170168
break
171169

172-
# Process tracks with limited concurrency to avoid DB overload
173-
174-
semaphore = asyncio.Semaphore(5) # Limit to 5 concurrent requests
175-
176-
async def get_track_with_limit(video_id: str) -> Track | None:
177-
async with semaphore:
178-
try:
179-
return await self.service_manager.provider.mass.music.tracks.get_provider_item(
180-
video_id, self.service_manager.provider.instance_id
181-
)
182-
except MediaNotFoundError:
183-
return None
184-
185-
# Execute with limited concurrency
186-
track_tasks = [get_track_with_limit(video_id) for video_id in video_ids]
170+
track_tasks = [self.service_manager.provider.get_track(video_id) for video_id in video_ids]
187171
tracks_results = await asyncio.gather(*track_tasks, return_exceptions=True)
188172

189173
# Filter successful results

0 commit comments

Comments
 (0)