fix: 修复数据库和 store 数据不一致问题

This commit is contained in:
kangfenmao 2024-10-23 14:08:48 +08:00
parent 6265d27ebc
commit b47d6c95e7
2 changed files with 18 additions and 2 deletions

View File

@ -22,7 +22,7 @@ const persistedReducer = persistReducer(
{ {
key: 'cherry-studio', key: 'cherry-studio',
storage, storage,
version: 33, version: 34,
blacklist: ['runtime'], blacklist: ['runtime'],
migrate migrate
}, },

View File

@ -1,7 +1,8 @@
import { SYSTEM_MODELS } from '@renderer/config/models' import { SYSTEM_MODELS } from '@renderer/config/models'
import db from '@renderer/databases'
import i18n from '@renderer/i18n' import i18n from '@renderer/i18n'
import { Assistant } from '@renderer/types' import { Assistant } from '@renderer/types'
import { uuid } from '@renderer/utils' import { runAsyncFunction, uuid } from '@renderer/utils'
import { isEmpty } from 'lodash' import { isEmpty } from 'lodash'
import { createMigrate } from 'redux-persist' import { createMigrate } from 'redux-persist'
@ -594,6 +595,21 @@ const migrateConfig = {
}) })
} }
} }
},
'34': (state: RootState) => {
state.assistants.assistants.forEach((assistant) => {
assistant.topics.forEach((topic) => {
topic.assistantId = assistant.id
runAsyncFunction(async () => {
const _topic = await db.topics.get(topic.id)
if (_topic) {
const messages = (_topic?.messages || []).map((message) => ({ ...message, assistantId: assistant.id }))
db.topics.put({ ..._topic, messages }, topic.id)
}
})
})
})
return state
} }
} }