DB: Message + Attachments in einer Transaktion speichern (1x fsync statt N+1)

This commit is contained in:
Meleki committed 2026-02-27 08:13:44 +01:00
1 parent 1271c9c651
commit 0b2c9a08c6
2 files changed
+43 -25

No files matched your search

+11 -17
View File
@@ -133,28 +133,22 @@ public static class ChatEndpoint
var attachmentInfos = lastUserMsg.GetAttachments();
var attachmentBlocks = lastUserMsg.GetAttachmentBlocks();
var messageId = await db.SaveMessage(new MessageRecord
var attachmentRecords = attachmentBlocks.Select(b => new AttachmentRecord
{
Type = b.Type,
MediaType = b.MediaType,
FileName = b.FileName,
Data = b.Data
}).ToList();
await db.SaveMessageWithAttachments(new MessageRecord
{
ChainId = chainId,
Iteration = 0,
Role = "user",
Type = "text",
Content = textContent,
AttachmentCount = attachmentBlocks.Count
});
// Attachments separat speichern
foreach (var block in attachmentBlocks)
{
await db.SaveAttachment(new AttachmentRecord
{
MessageId = messageId,
Type = block.Type,
MediaType = block.MediaType,
FileName = block.FileName,
Data = block.Data
});
}
Content = textContent
}, attachmentRecords);
}
var systemPrompt = new List<object>