mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 12:12:09 +01:00
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:
@ -119,6 +119,14 @@ async function parseTranscriptIntoMessages(
|
||||
|
||||
// Split transcript into lines and parse each message
|
||||
const lines = transcriptContent.split("\n").filter((line) => line.trim());
|
||||
const messagesToCreate: Array<{
|
||||
sessionId: string;
|
||||
timestamp: Date | null;
|
||||
role: string;
|
||||
content: string;
|
||||
order: number;
|
||||
}> = [];
|
||||
|
||||
let order = 0;
|
||||
|
||||
for (const line of lines) {
|
||||
@ -158,22 +166,28 @@ async function parseTranscriptIntoMessages(
|
||||
// Skip empty content
|
||||
if (!content) continue;
|
||||
|
||||
// Create message record
|
||||
await prisma.message.create({
|
||||
data: {
|
||||
sessionId,
|
||||
timestamp,
|
||||
role,
|
||||
content,
|
||||
order,
|
||||
},
|
||||
// Collect message data for batch creation
|
||||
messagesToCreate.push({
|
||||
sessionId,
|
||||
timestamp,
|
||||
role,
|
||||
content,
|
||||
order,
|
||||
});
|
||||
|
||||
order++;
|
||||
}
|
||||
|
||||
// Batch create all messages at once for better performance
|
||||
if (messagesToCreate.length > 0) {
|
||||
await prisma.message.createMany({
|
||||
data: messagesToCreate,
|
||||
skipDuplicates: true, // Prevents errors on unique constraint violations
|
||||
});
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[Import Processor] ✓ Parsed ${order} messages for session ${sessionId}`
|
||||
`[Import Processor] ✓ Parsed ${messagesToCreate.length} messages for session ${sessionId} (batch operation)`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user