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

@ -90,6 +90,13 @@ class PerformanceTracker {
},
};
}
reset(): void {
this.metrics = {
optimized: { totalTime: 0, operationCount: 0, errorCount: 0 },
original: { totalTime: 0, operationCount: 0, errorCount: 0 },
};
}
}
const performanceTracker = new PerformanceTracker();
@ -205,7 +212,30 @@ export const IntegratedBatchProcessor = {
getBatchProcessingStats: async (companyId?: string) => {
return executeWithTracking(
() => OptimizedProcessor.getBatchProcessingStatsOptimized(companyId),
() => OriginalProcessor.getBatchProcessingStats(companyId || ""),
async () => {
// Adapter function to transform original output to match optimized output
const originalResult = await OriginalProcessor.getBatchProcessingStats(
companyId || ""
);
const batchStats = originalResult.batchStats as Record<string, number>;
return {
totalBatches: Object.values(batchStats).reduce(
(sum, count) => sum + count,
0
),
pendingRequests: originalResult.pendingRequests,
inProgressBatches:
(batchStats["IN_PROGRESS"] || 0) +
(batchStats["VALIDATING"] || 0) +
(batchStats["UPLOADING"] || 0) +
(batchStats["FINALIZING"] || 0),
completedBatches:
(batchStats["COMPLETED"] || 0) + (batchStats["PROCESSED"] || 0),
failedRequests:
(batchStats["FAILED"] || 0) + (batchStats["CANCELLED"] || 0),
};
},
"getBatchProcessingStats"
);
},
@ -303,10 +333,7 @@ export const IntegratedBatchProcessor = {
* Reset performance tracking (useful for testing)
*/
resetPerformanceTracking: (): void => {
performanceTracker.metrics = {
optimized: { totalTime: 0, operationCount: 0, errorCount: 0 },
original: { totalTime: 0, operationCount: 0, errorCount: 0 },
};
performanceTracker.reset();
},
};