fix(topic): clear related message_blocks when clearing topic messages (#11665)

Ensure message_blocks rows are removed when clearing a topic's messages to avoid orphaned block entries.

Signed-off-by: Do1e <i@do1e.cn>
This commit is contained in:
Peijie Diao 2025-12-04 22:32:37 +08:00 committed by GitHub
parent a2a6c62f48
commit 6343628739
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -195,13 +195,8 @@ export const TopicManager = {
}, },
async removeTopic(id: string) { async removeTopic(id: string) {
const messages = await TopicManager.getTopicMessages(id) await TopicManager.clearTopicMessages(id)
await db.topics.delete(id)
for (const message of messages) {
await deleteMessageFiles(message)
}
db.topics.delete(id)
}, },
async clearTopicMessages(id: string) { async clearTopicMessages(id: string) {
@ -212,6 +207,12 @@ export const TopicManager = {
await deleteMessageFiles(message) await deleteMessageFiles(message)
} }
// 删除关联的 message_blocks 记录
const blockIds = topic.messages.flatMap((message) => message.blocks || [])
if (blockIds.length > 0) {
await db.message_blocks.bulkDelete(blockIds)
}
topic.messages = [] topic.messages = []
await db.topics.update(id, topic) await db.topics.update(id, topic)