cherry-studio/check-duplicate-messages.js
1600822305 53643e81f0 升级
2025-04-20 01:46:29 +08:00

78 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 检查重复消息的脚本
const { app } = require('electron')
const path = require('path')
const fs = require('fs')
// 获取数据库文件路径
const userDataPath = app.getPath('userData')
const dbFilePath = path.join(userDataPath, 'CherryStudio.db')
console.log('数据库文件路径:', dbFilePath)
// 检查文件是否存在
if (fs.existsSync(dbFilePath)) {
console.log('数据库文件存在')
// 读取数据库内容
const dbContent = fs.readFileSync(dbFilePath, 'utf8')
// 解析数据库内容
try {
const data = JSON.parse(dbContent)
// 检查topics表中的消息
if (data.topics) {
console.log('找到topics表共有', data.topics.length, '个主题')
// 遍历每个主题
data.topics.forEach((topic) => {
console.log(`检查主题: ${topic.id}`)
if (topic.messages && Array.isArray(topic.messages)) {
console.log(` 主题消息数量: ${topic.messages.length}`)
// 检查重复消息
const messageIds = new Set()
const duplicates = []
topic.messages.forEach((message) => {
if (messageIds.has(message.id)) {
duplicates.push(message.id)
} else {
messageIds.add(message.id)
}
})
if (duplicates.length > 0) {
console.log(` 发现${duplicates.length}条重复消息ID:`, duplicates)
} else {
console.log(' 未发现重复消息ID')
}
// 检查重复的askId (对于助手消息)
const askIds = {}
topic.messages.forEach((message) => {
if (message.role === 'assistant' && message.askId) {
if (!askIds[message.askId]) {
askIds[message.askId] = []
}
askIds[message.askId].push(message.id)
}
})
// 输出每个askId对应的助手消息数量
Object.entries(askIds).forEach(([askId, messageIds]) => {
if (messageIds.length > 1) {
console.log(` askId ${askId}${messageIds.length} 条助手消息`)
}
})
}
})
}
} catch (error) {
console.error('解析数据库内容失败:', error)
}
} else {
console.log('数据库文件不存在')
}