This commit is contained in:
+61
-1
@@ -16,6 +16,9 @@ from .models import SonarrWebhook, RadarrWebhook, HealthResponse, TVSeasonReques
|
||||
# Import core utilities
|
||||
from core.logging import _log
|
||||
from core.database import NFOGuardDatabase
|
||||
from core.fs_cache import fs_cache, clear_all_caches
|
||||
from core.xml_cache import xml_cache
|
||||
from core.batch_operations import optimize_library_scan
|
||||
|
||||
|
||||
async def _read_payload(request: Request) -> Optional[Dict[str, Any]]:
|
||||
@@ -260,4 +263,61 @@ def register_routes(
|
||||
@app.post("/bulk/update")
|
||||
async def bulk_update():
|
||||
"""Bulk update functionality"""
|
||||
return {"message": "Bulk update - implementation needed"}
|
||||
return {"message": "Bulk update - implementation needed"}
|
||||
|
||||
# Performance monitoring endpoints
|
||||
@app.get("/cache/stats")
|
||||
async def cache_stats():
|
||||
"""Get comprehensive cache performance statistics"""
|
||||
fs_stats = fs_cache.get_cache_stats()
|
||||
xml_stats = xml_cache.get_cache_stats()
|
||||
|
||||
# Combine stats
|
||||
combined_stats = {
|
||||
"filesystem_cache": fs_stats,
|
||||
"xml_processing_cache": xml_stats,
|
||||
"overall_hit_rate": round(
|
||||
((fs_stats["cache_hits"] + xml_stats["xml_cache_hits"]) /
|
||||
(fs_stats["cache_hits"] + fs_stats["cache_misses"] +
|
||||
xml_stats["xml_cache_hits"] + xml_stats["xml_cache_misses"]) * 100
|
||||
) if (fs_stats["cache_hits"] + fs_stats["cache_misses"] +
|
||||
xml_stats["xml_cache_hits"] + xml_stats["xml_cache_misses"]) > 0 else 0, 2
|
||||
)
|
||||
}
|
||||
|
||||
return combined_stats
|
||||
|
||||
@app.post("/cache/clear")
|
||||
async def clear_cache():
|
||||
"""Clear all caches"""
|
||||
clear_all_caches()
|
||||
return {"status": "success", "message": "All caches cleared"}
|
||||
|
||||
@app.post("/scan/optimized")
|
||||
async def optimized_scan(background_tasks: BackgroundTasks):
|
||||
"""Trigger optimized library scan using batch operations"""
|
||||
try:
|
||||
_log("INFO", "Optimized scan triggered via API")
|
||||
|
||||
def run_optimized_scan():
|
||||
# Combine all library paths
|
||||
all_paths = list(config.tv_paths) + list(config.movie_paths)
|
||||
existing_paths = [p for p in all_paths if p.exists()]
|
||||
|
||||
if not existing_paths:
|
||||
_log("WARNING", "No valid library paths found")
|
||||
return
|
||||
|
||||
# Run optimized scan
|
||||
results = optimize_library_scan(existing_paths)
|
||||
_log("INFO", f"Optimized scan complete: {results}")
|
||||
|
||||
background_tasks.add_task(run_optimized_scan)
|
||||
return {
|
||||
"status": "started",
|
||||
"message": "Optimized library scan initiated",
|
||||
"note": "Uses batch operations and caching for improved performance"
|
||||
}
|
||||
except Exception as e:
|
||||
_log("ERROR", f"Optimized scan failed: {e}")
|
||||
raise HTTPException(status_code=500, detail=f"Optimized scan failed: {str(e)}")
|
||||
Reference in New Issue
Block a user