Add cache control artwork stats
This commit is contained in:
@@ -10,6 +10,7 @@ from ..db import (
|
||||
get_all_users,
|
||||
get_request_cache_overview,
|
||||
get_request_cache_missing_titles,
|
||||
get_request_cache_count,
|
||||
get_settings_overrides,
|
||||
get_user_by_username,
|
||||
set_setting,
|
||||
@@ -38,6 +39,22 @@ from ..routers.branding import save_branding_image
|
||||
router = APIRouter(prefix="/admin", tags=["admin"], dependencies=[Depends(require_admin)])
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def _get_artwork_cache_stats() -> Dict[str, int]:
|
||||
cache_root = os.path.join(os.getcwd(), "data", "artwork")
|
||||
total_bytes = 0
|
||||
total_files = 0
|
||||
if not os.path.isdir(cache_root):
|
||||
return {"cache_bytes": 0, "cache_files": 0}
|
||||
for root, _, files in os.walk(cache_root):
|
||||
for name in files:
|
||||
path = os.path.join(root, name)
|
||||
try:
|
||||
total_bytes += os.path.getsize(path)
|
||||
total_files += 1
|
||||
except OSError:
|
||||
continue
|
||||
return {"cache_bytes": total_bytes, "cache_files": total_files}
|
||||
|
||||
SENSITIVE_KEYS = {
|
||||
"jellyseerr_api_key",
|
||||
"jellyfin_api_key",
|
||||
@@ -277,10 +294,12 @@ async def requests_sync_delta() -> Dict[str, Any]:
|
||||
|
||||
|
||||
@router.post("/requests/artwork/prefetch")
|
||||
async def requests_artwork_prefetch() -> Dict[str, Any]:
|
||||
async def requests_artwork_prefetch(only_missing: bool = False) -> Dict[str, Any]:
|
||||
runtime = get_runtime_settings()
|
||||
state = await requests_router.start_artwork_prefetch(
|
||||
runtime.jellyseerr_base_url, runtime.jellyseerr_api_key
|
||||
runtime.jellyseerr_base_url,
|
||||
runtime.jellyseerr_api_key,
|
||||
only_missing=only_missing,
|
||||
)
|
||||
logger.info("Admin triggered artwork prefetch: status=%s", state.get("status"))
|
||||
return {"status": "ok", "prefetch": state}
|
||||
@@ -290,6 +309,17 @@ async def requests_artwork_prefetch() -> Dict[str, Any]:
|
||||
async def requests_artwork_status() -> Dict[str, Any]:
|
||||
return {"status": "ok", "prefetch": requests_router.get_artwork_prefetch_state()}
|
||||
|
||||
@router.get("/requests/artwork/summary")
|
||||
async def requests_artwork_summary() -> Dict[str, Any]:
|
||||
runtime = get_runtime_settings()
|
||||
summary = {
|
||||
"total_requests": get_request_cache_count(),
|
||||
"missing_artwork": requests_router.get_artwork_cache_missing_count(),
|
||||
"cache_mode": (runtime.artwork_cache_mode or "remote").lower(),
|
||||
}
|
||||
summary.update(_get_artwork_cache_stats())
|
||||
return {"status": "ok", "summary": summary}
|
||||
|
||||
|
||||
@router.get("/requests/sync/status")
|
||||
async def requests_sync_status() -> Dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user