feat: implement cache layer, CSP improvements, and database performance optimizations

- Add Redis cache implementation with LRU eviction
- Enhance Content Security Policy with nonce generation
- Optimize database queries with connection pooling
- Add cache invalidation API endpoints
- Improve security monitoring performance
This commit is contained in:
2025-07-12 04:44:50 +02:00
parent 7a3eabccd9
commit e1abedb148
56 changed files with 6881 additions and 7040 deletions

View File

@ -61,10 +61,10 @@ function SessionLocationInfo({ session }: { session: ChatSession }) {
Location & Language
</h4>
<div className="space-y-2">
{session.countryCode && (
{session.country && (
<div className="flex items-center gap-2">
<span className="text-xs text-muted-foreground">Country:</span>
<CountryDisplay countryCode={session.countryCode} />
<CountryDisplay countryCode={session.country} />
</div>
)}
{session.language && (

View File

@ -274,7 +274,12 @@ export default function BatchMonitoringDashboard() {
};
const getHealthStatus = () => {
if (!monitoringData) return { status: "unknown", color: "gray" };
if (!monitoringData)
return {
status: "unknown",
color: "gray",
message: "No monitoring data",
};
const { systemHealth } = monitoringData;
@ -407,8 +412,13 @@ export default function BatchMonitoringDashboard() {
return (
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
<SystemHealthCard health={health} schedulerStatus={schedulerStatus} />
<CircuitBreakerCard circuitBreakerStatus={circuitBreakerStatus} />
<SystemHealthCard
health={health}
schedulerStatus={schedulerStatus as any}
/>
<CircuitBreakerCard
circuitBreakerStatus={circuitBreakerStatus as any}
/>
</div>
);
};

View File

@ -15,7 +15,7 @@ import {
useEffect,
useState,
} from "react";
import { CSRFClient } from "../../lib/csrf";
import { CSRFClient } from "../../lib/csrf-client";
interface CSRFContextType {
token: string | null;

View File

@ -21,11 +21,36 @@ export function TRPCProvider({ children }: TRPCProviderProps) {
new QueryClient({
defaultOptions: {
queries: {
// Disable automatic refetching for better UX
// Optimize refetching behavior for better performance
refetchOnWindowFocus: false,
refetchOnReconnect: true,
staleTime: 30 * 1000, // 30 seconds
gcTime: 5 * 60 * 1000, // 5 minutes (was cacheTime)
refetchOnMount: false, // Only refetch if stale
retry: (failureCount, error) => {
// Smart retry logic based on error type
if (
error?.message?.includes("401") ||
error?.message?.includes("403")
) {
return false; // Don't retry auth errors
}
return failureCount < 3;
},
retryDelay: (attemptIndex) =>
Math.min(1000 * 2 ** attemptIndex, 30000),
// Optimized cache times based on data type
staleTime: 2 * 60 * 1000, // 2 minutes - data is fresh for 2 minutes
gcTime: 10 * 60 * 1000, // 10 minutes - keep unused data for 10 minutes
// Performance optimizations
networkMode: "online", // Only run queries when online
notifyOnChangeProps: ["data", "error", "isLoading"], // Reduce re-renders
},
mutations: {
// Optimize mutation behavior
retry: 2,
networkMode: "online",
throwOnError: false, // Handle errors gracefully in components
},
},
})