Fix cache title hydration
This commit is contained in:
@@ -9,6 +9,7 @@ from ..db import (
|
||||
delete_setting,
|
||||
get_all_users,
|
||||
get_request_cache_overview,
|
||||
get_request_cache_missing_titles,
|
||||
get_settings_overrides,
|
||||
get_user_by_username,
|
||||
set_setting,
|
||||
@@ -100,6 +101,38 @@ def _normalize_root_folders(folders: Any) -> List[Dict[str, Any]]:
|
||||
return results
|
||||
|
||||
|
||||
async def _hydrate_cache_titles_from_jellyseerr(limit: int) -> int:
|
||||
runtime = get_runtime_settings()
|
||||
client = JellyseerrClient(runtime.jellyseerr_base_url, runtime.jellyseerr_api_key)
|
||||
if not client.configured():
|
||||
return 0
|
||||
missing = get_request_cache_missing_titles(limit)
|
||||
if not missing:
|
||||
return 0
|
||||
hydrated = 0
|
||||
for row in missing:
|
||||
tmdb_id = row.get("tmdb_id")
|
||||
media_type = row.get("media_type")
|
||||
request_id = row.get("request_id")
|
||||
if not tmdb_id or not media_type or not request_id:
|
||||
continue
|
||||
try:
|
||||
title, year = await requests_router._hydrate_title_from_tmdb(
|
||||
client, media_type, tmdb_id
|
||||
)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
"Requests cache title hydrate failed: request_id=%s tmdb_id=%s",
|
||||
request_id,
|
||||
tmdb_id,
|
||||
)
|
||||
continue
|
||||
if title:
|
||||
update_request_cache_title(request_id, title, year)
|
||||
hydrated += 1
|
||||
return hydrated
|
||||
|
||||
|
||||
def _normalize_quality_profiles(profiles: Any) -> List[Dict[str, Any]]:
|
||||
if not isinstance(profiles, list):
|
||||
return []
|
||||
@@ -286,6 +319,9 @@ async def requests_cache(limit: int = 50) -> Dict[str, Any]:
|
||||
repaired = repair_request_cache_titles()
|
||||
if repaired:
|
||||
logger.info("Requests cache titles repaired via settings view: %s", repaired)
|
||||
hydrated = await _hydrate_cache_titles_from_jellyseerr(limit)
|
||||
if hydrated:
|
||||
logger.info("Requests cache titles hydrated via Jellyseerr: %s", hydrated)
|
||||
rows = get_request_cache_overview(limit)
|
||||
return {"rows": rows}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user