mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-02-05 17:15:19 -05:00
feat: Implement initial schema and add various API, service, and management command enhancements across the application.
This commit is contained in:
@@ -30,7 +30,7 @@ class FallbackCacheMonitor:
|
||||
"""Fallback class if CacheMonitor is not available."""
|
||||
|
||||
def get_cache_stats(self):
|
||||
return {"error": "Cache monitoring not available"}
|
||||
return {"detail": "Cache monitoring not available"}
|
||||
|
||||
|
||||
class FallbackIndexAnalyzer:
|
||||
@@ -38,7 +38,7 @@ class FallbackIndexAnalyzer:
|
||||
|
||||
@staticmethod
|
||||
def analyze_slow_queries(threshold):
|
||||
return {"error": "Query analysis not available"}
|
||||
return {"detail": "Query analysis not available"}
|
||||
|
||||
|
||||
# Try to import the real classes, use fallbacks if not available
|
||||
@@ -56,9 +56,7 @@ except ImportError:
|
||||
@extend_schema_view(
|
||||
get=extend_schema(
|
||||
summary="Health check",
|
||||
description=(
|
||||
"Get comprehensive health check information including system metrics."
|
||||
),
|
||||
description=("Get comprehensive health check information including system metrics."),
|
||||
responses={
|
||||
200: HealthCheckOutputSerializer,
|
||||
503: HealthCheckOutputSerializer,
|
||||
@@ -88,7 +86,7 @@ class HealthCheckAPIView(APIView):
|
||||
cache_monitor = CacheMonitor()
|
||||
cache_stats = cache_monitor.get_cache_stats()
|
||||
except Exception:
|
||||
cache_stats = {"error": "Cache monitoring unavailable"}
|
||||
cache_stats = {"detail": "Cache monitoring unavailable"}
|
||||
|
||||
# Build comprehensive health data
|
||||
health_data = {
|
||||
@@ -120,9 +118,7 @@ class HealthCheckAPIView(APIView):
|
||||
critical_service = False
|
||||
response_time = None
|
||||
|
||||
plugin_errors = (
|
||||
errors.get(plugin_class_name, []) if isinstance(errors, dict) else []
|
||||
)
|
||||
plugin_errors = errors.get(plugin_class_name, []) if isinstance(errors, dict) else []
|
||||
|
||||
health_data["checks"][plugin_name] = {
|
||||
"status": "healthy" if not plugin_errors else "unhealthy",
|
||||
@@ -194,9 +190,7 @@ class HealthCheckAPIView(APIView):
|
||||
"transactions_committed": row[1],
|
||||
"transactions_rolled_back": row[2],
|
||||
"cache_hit_ratio": (
|
||||
round((row[4] / (row[3] + row[4])) * 100, 2)
|
||||
if (row[3] + row[4]) > 0
|
||||
else 0
|
||||
round((row[4] / (row[3] + row[4])) * 100, 2) if (row[3] + row[4]) > 0 else 0
|
||||
),
|
||||
}
|
||||
)
|
||||
@@ -206,7 +200,7 @@ class HealthCheckAPIView(APIView):
|
||||
return metrics
|
||||
|
||||
except Exception as e:
|
||||
return {"connection_status": "error", "error": str(e)}
|
||||
return {"connection_status": "error", "detail": str(e)}
|
||||
|
||||
def _get_system_metrics(self) -> dict:
|
||||
"""Get system performance metrics."""
|
||||
@@ -270,7 +264,7 @@ class PerformanceMetricsAPIView(APIView):
|
||||
def get(self, request: Request) -> Response:
|
||||
"""Return performance metrics and analysis."""
|
||||
if not settings.DEBUG:
|
||||
return Response({"error": "Only available in debug mode"}, status=403)
|
||||
return Response({"detail": "Only available in debug mode"}, status=403)
|
||||
|
||||
metrics = {
|
||||
"timestamp": timezone.now(),
|
||||
@@ -306,7 +300,7 @@ class PerformanceMetricsAPIView(APIView):
|
||||
return analysis
|
||||
|
||||
except Exception as e:
|
||||
return {"error": str(e)}
|
||||
return {"detail": str(e)}
|
||||
|
||||
def _get_cache_performance(self):
|
||||
"""Get cache performance metrics."""
|
||||
@@ -314,14 +308,14 @@ class PerformanceMetricsAPIView(APIView):
|
||||
cache_monitor = CacheMonitor()
|
||||
return cache_monitor.get_cache_stats()
|
||||
except Exception as e:
|
||||
return {"error": str(e)}
|
||||
return {"detail": str(e)}
|
||||
|
||||
def _get_slow_queries(self):
|
||||
"""Get recent slow queries."""
|
||||
try:
|
||||
return IndexAnalyzer.analyze_slow_queries(0.1) # 100ms threshold
|
||||
except Exception as e:
|
||||
return {"error": str(e)}
|
||||
return {"detail": str(e)}
|
||||
|
||||
|
||||
@extend_schema_view(
|
||||
@@ -336,9 +330,7 @@ class PerformanceMetricsAPIView(APIView):
|
||||
),
|
||||
options=extend_schema(
|
||||
summary="CORS preflight for simple health check",
|
||||
description=(
|
||||
"Handle CORS preflight requests for the simple health check endpoint."
|
||||
),
|
||||
description=("Handle CORS preflight requests for the simple health check endpoint."),
|
||||
responses={
|
||||
200: SimpleHealthOutputSerializer,
|
||||
},
|
||||
@@ -370,7 +362,7 @@ class SimpleHealthAPIView(APIView):
|
||||
except Exception as e:
|
||||
response_data = {
|
||||
"status": "error",
|
||||
"error": str(e),
|
||||
"detail": str(e),
|
||||
"timestamp": timezone.now(),
|
||||
}
|
||||
serializer = SimpleHealthOutputSerializer(response_data)
|
||||
|
||||
Reference in New Issue
Block a user