mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +08:00
refactor(data): remove pluginCompute plugin-compute path
图表已统一走缓存端点,pluginCompute 不再被任何调用方使用,移除其全链路实现。 pluginQuery 保留供消息浏览/搜索/分页与 session-index 等通用 SQL 访问。 - 删除 ElectronDataAdapter(已无覆写),electron registry 直接使用 FetchDataAdapter - 移除 IPC handler、preload API/类型、worker dispatch 与 workerManager 导出中的 pluginCompute Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
93608fa5eb
commit
cc4e67bd24
7 files changed
+3
-45
No files matched your search
@@ -236,14 +236,6 @@ 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).
|
||||
|
||||
@@ -217,12 +217,8 @@ const syncHandlers: Record<string, (payload: any) => any> = {
|
||||
executeRawSQL: (p) => executeRawSQL(p.sessionId, p.sql),
|
||||
getSchema: (p) => getSchema(p.sessionId),
|
||||
|
||||
// 插件系统
|
||||
// 通用 SQL 查询
|
||||
pluginQuery: (p) => executePluginQuery(p.sessionId, p.sql, p.params),
|
||||
pluginCompute: (p: { fnString: string; input: any }) => {
|
||||
const fn = new Function('return ' + p.fnString)()
|
||||
return fn(p.input)
|
||||
},
|
||||
|
||||
// 会话索引
|
||||
generateSessions: (p) => generateSessions(p.sessionId, p.gapThreshold),
|
||||
|
||||
@@ -257,14 +257,6 @@ export async function pluginQuery<T = Record<string, any>>(
|
||||
return sendToWorker('pluginQuery', { sessionId, sql, params }, 120000)
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件计算卸载(纯函数在 Worker 中执行)
|
||||
* 超时设为 120s,因为计算密集型任务 + 排队等待可能较长
|
||||
*/
|
||||
export async function pluginCompute<TOutput = any>(fnString: string, input: any): Promise<TOutput> {
|
||||
return sendToWorker('pluginCompute', { fnString, input }, 120000)
|
||||
}
|
||||
|
||||
// ==================== 导出的异步 API ====================
|
||||
|
||||
export async function getAvailableYears(sessionId: string): Promise<number[]> {
|
||||
|
||||
@@ -78,13 +78,6 @@ 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,7 +73,6 @@ 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
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* 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 { ElectronDataAdapter } = await import('./data/electron')
|
||||
registerAdapter('data', new ElectronDataAdapter())
|
||||
const { FetchDataAdapter } = await import('./data/fetch')
|
||||
registerAdapter('data', new FetchDataAdapter())
|
||||
|
||||
const { ElectronImportAdapter } = await import('./import/electron')
|
||||
registerAdapter('import', new ElectronImportAdapter())
|
||||
|
||||
Reference in new issue
Block a user