Improve cache stats performance (build 271261145)

This commit is contained in:
2026-01-27 11:46:50 +13:00
parent 3f51e24181
commit 7c97934bb9
4 changed files with 307 additions and 51 deletions

View File

@@ -10,7 +10,7 @@ from ..db import (
get_all_users,
get_request_cache_overview,
get_request_cache_missing_titles,
get_request_cache_count,
get_request_cache_stats,
get_settings_overrides,
get_user_by_username,
set_setting,
@@ -39,22 +39,6 @@ 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",
@@ -312,12 +296,20 @@ async def requests_artwork_status() -> Dict[str, Any]:
@router.get("/requests/artwork/summary")
async def requests_artwork_summary() -> Dict[str, Any]:
runtime = get_runtime_settings()
cache_mode = (runtime.artwork_cache_mode or "remote").lower()
stats = get_request_cache_stats()
if cache_mode != "cache":
stats["cache_bytes"] = 0
stats["cache_files"] = 0
stats["missing_artwork"] = 0
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(),
"cache_mode": cache_mode,
"cache_bytes": stats.get("cache_bytes", 0),
"cache_files": stats.get("cache_files", 0),
"missing_artwork": stats.get("missing_artwork", 0),
"total_requests": stats.get("total_requests", 0),
"updated_at": stats.get("updated_at"),
}
summary.update(_get_artwork_cache_stats())
return {"status": "ok", "summary": summary}