44
55from loguru import logger
66
7+ from app .core .config import settings
78from app .core .settings import UserSettings
89from app .services .discovery import DiscoveryEngine
910from app .services .profile .service import UserProfileService
@@ -334,7 +335,6 @@ async def _get_genre_whitelist(self, content_type: str, scored_objects: list | N
334335 if content_type in self ._whitelist_cache :
335336 return self ._whitelist_cache [content_type ]
336337
337- # Logic from _get_top_genre_whitelist
338338 try :
339339 if scored_objects is None :
340340 if self ._library_data is None :
@@ -346,6 +346,7 @@ async def _get_genre_whitelist(self, content_type: str, scored_objects: list | N
346346 self ._library_data .get ("loved" , [])
347347 + self ._library_data .get ("watched" , [])
348348 + self ._library_data .get ("added" , [])
349+ + self ._library_data .get ("liked" , [])
349350 )
350351 typed = [
351352 it
@@ -357,7 +358,9 @@ async def _get_genre_whitelist(self, content_type: str, scored_objects: list | N
357358 key = lambda x : x .get ("state" , {}).get ("lastWatched" ) or "" ,
358359 reverse = True ,
359360 )
360- scored_objects = [self .scoring_service .process_item (it ) for it in sorted_hist [:10 ]]
361+ scored_objects = [
362+ self .scoring_service .process_item (it ) for it in sorted_hist [: settings .LIBRARY_ITEMS_LIMIT ]
363+ ]
361364
362365 prof_type = "series" if content_type in ("tv" , "series" ) else "movie"
363366 temp_profile = await self .user_profile_service .build_user_profile (scored_objects , content_type = prof_type )
@@ -634,11 +637,13 @@ async def get_recommendations_for_theme(self, theme_id: str, content_type: str,
634637 whitelist = await self ._get_genre_whitelist (content_type )
635638 candidates = []
636639 try :
637- for p in [1 , 2 , 3 ]:
638- res = await self .tmdb_service .get_discover (content_type , page = p , ** params )
640+ discover_tasks = [self .tmdb_service .get_discover (content_type , page = p , ** params ) for p in [1 , 2 , 3 ]]
641+ discover_results = await asyncio .gather (* discover_tasks , return_exceptions = True )
642+ for res in discover_results :
643+ if isinstance (res , Exception ):
644+ logger .error (f"Error fetching discover for { content_type } : { res } " )
645+ continue
639646 candidates .extend (res .get ("results" , []))
640- if len (candidates ) >= limit * 2 :
641- break
642647 except Exception :
643648 pass
644649
0 commit comments