mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +08:00
fix(electron): offload chart plugin compute to worker
This commit is contained in:
1 parent
d96299b16e
commit
eea1dad907
5 files changed
+32
-2
No files matched your search
@@ -234,6 +234,14 @@ export function registerChatHandlers(ctx: IpcContext): void {
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 仅保留图表插件计算的 worker 卸载路径。
|
||||
* 其他数据查询已迁移到 HTTP,但这些计算会处理大数组,放在 renderer 会冻结 UI。
|
||||
*/
|
||||
ipcMain.handle('chat:pluginCompute', async (_, fnString: string, input: unknown) => {
|
||||
return worker.pluginCompute(fnString, input)
|
||||
})
|
||||
|
||||
// Session index and summary IPC handlers have been removed.
|
||||
// All session-index operations now go through shared HTTP routes
|
||||
// (FetchSessionIndexAdapter via /_web/sessions/* endpoints).
|
||||
|
||||
@@ -78,6 +78,13 @@ export const chatApi = {
|
||||
): Promise<{ success: boolean; newMessageCount: number; error?: string }> =>
|
||||
ipcRenderer.invoke('chat:incrementalImport', sessionId, filePath),
|
||||
|
||||
/**
|
||||
* 图表插件计算会处理大量消息数组,Electron 下必须卸载到 worker,
|
||||
* 避免 renderer 主线程同步执行造成窗口卡顿。
|
||||
*/
|
||||
pluginCompute: <T = unknown>(fnString: string, input: unknown): Promise<T> =>
|
||||
ipcRenderer.invoke('chat:pluginCompute', fnString, input),
|
||||
|
||||
// ==================== Demo ====================
|
||||
|
||||
importDemo: (
|
||||
|
||||
Vendored
+1
@@ -73,6 +73,7 @@ interface ChatApi {
|
||||
sessionId: string,
|
||||
filePath: string
|
||||
) => Promise<{ success: boolean; newMessageCount: number; error?: string }>
|
||||
pluginCompute: <T = unknown>(fnString: string, input: unknown) => Promise<T>
|
||||
importDemo: (locale: string) => Promise<{
|
||||
success: boolean
|
||||
groupSessionId?: string
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* ElectronDataAdapter — Electron 专用 DataAdapter
|
||||
*
|
||||
* 普通数据查询继续复用共享 HTTP 路由;计算密集型 pluginCompute
|
||||
* 通过 Electron worker 执行,避免在 renderer 主线程同步阻塞图表交互。
|
||||
*/
|
||||
|
||||
import { FetchDataAdapter } from './fetch'
|
||||
|
||||
export class ElectronDataAdapter extends FetchDataAdapter {
|
||||
async pluginCompute<T = unknown>(fnString: string, input: unknown): Promise<T> {
|
||||
return window.chatApi.pluginCompute<T>(fnString, input)
|
||||
}
|
||||
}
|
||||
@@ -65,8 +65,8 @@ export async function initServices(): Promise<void> {
|
||||
* data/message/preferences/ai-streaming use Fetch/SSE; import stays on IPC.
|
||||
*/
|
||||
async function initElectronAdapters(): Promise<void> {
|
||||
const { FetchDataAdapter } = await import('./data/fetch')
|
||||
registerAdapter('data', new FetchDataAdapter())
|
||||
const { ElectronDataAdapter } = await import('./data/electron')
|
||||
registerAdapter('data', new ElectronDataAdapter())
|
||||
|
||||
const { ElectronImportAdapter } = await import('./import/electron')
|
||||
registerAdapter('import', new ElectronImportAdapter())
|
||||
|
||||
Reference in new issue
Block a user