mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 14:41:24 +08:00
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:
parent
a2a6c62f48
commit
6343628739
@ -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)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user