From b47d6c95e7025bedd623b6bc41f707b9ad6ee761 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Wed, 23 Oct 2024 14:08:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=92=8C=20store=20=E6=95=B0=E6=8D=AE=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/store/index.ts | 2 +- src/renderer/src/store/migrate.ts | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/store/index.ts b/src/renderer/src/store/index.ts index cf6a7dbf..7b8f039e 100644 --- a/src/renderer/src/store/index.ts +++ b/src/renderer/src/store/index.ts @@ -22,7 +22,7 @@ const persistedReducer = persistReducer( { key: 'cherry-studio', storage, - version: 33, + version: 34, blacklist: ['runtime'], migrate }, diff --git a/src/renderer/src/store/migrate.ts b/src/renderer/src/store/migrate.ts index bc1b1939..39a83752 100644 --- a/src/renderer/src/store/migrate.ts +++ b/src/renderer/src/store/migrate.ts @@ -1,7 +1,8 @@ import { SYSTEM_MODELS } from '@renderer/config/models' +import db from '@renderer/databases' import i18n from '@renderer/i18n' import { Assistant } from '@renderer/types' -import { uuid } from '@renderer/utils' +import { runAsyncFunction, uuid } from '@renderer/utils' import { isEmpty } from 'lodash' 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 } }