perf(export): prioritize totals and keep table visible

This commit is contained in:
tisonhuang
2026-03-01 17:27:10 +08:00
parent d12c111684
commit bf9b5ba593
6 changed files with 216 additions and 59 deletions

View File

@@ -916,6 +916,10 @@ function registerIpcHandlers() {
return chatService.getExportTabCounts()
})
ipcMain.handle('chat:getSessionMessageCounts', async (_, sessionIds: string[]) => {
return chatService.getSessionMessageCounts(sessionIds)
})
ipcMain.handle('chat:enrichSessionsContactInfo', async (_, usernames: string[]) => {
return chatService.enrichSessionsContactInfo(usernames)
})

View File

@@ -131,6 +131,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
connect: () => ipcRenderer.invoke('chat:connect'),
getSessions: () => ipcRenderer.invoke('chat:getSessions'),
getExportTabCounts: () => ipcRenderer.invoke('chat:getExportTabCounts'),
getSessionMessageCounts: (sessionIds: string[]) => ipcRenderer.invoke('chat:getSessionMessageCounts', sessionIds),
enrichSessionsContactInfo: (usernames: string[]) =>
ipcRenderer.invoke('chat:enrichSessionsContactInfo', usernames),
getMessages: (sessionId: string, offset?: number, limit?: number, startTime?: number, endTime?: number, ascending?: boolean) =>

View File

@@ -770,6 +770,48 @@ class ChatService {
}
}
/**
* 批量获取会话消息总数(轻量接口,用于列表优先排序)
*/
async getSessionMessageCounts(sessionIds: string[]): Promise<{
success: boolean
counts?: Record<string, number>
error?: string
}> {
try {
const connectResult = await this.ensureConnected()
if (!connectResult.success) {
return { success: false, error: connectResult.error || '数据库未连接' }
}
const normalizedSessionIds = Array.from(
new Set(
(sessionIds || [])
.map((id) => String(id || '').trim())
.filter(Boolean)
)
)
if (normalizedSessionIds.length === 0) {
return { success: true, counts: {} }
}
const counts: Record<string, number> = {}
await this.forEachWithConcurrency(normalizedSessionIds, 8, async (sessionId) => {
try {
const result = await wcdbService.getMessageCount(sessionId)
counts[sessionId] = result.success && typeof result.count === 'number' ? result.count : 0
} catch {
counts[sessionId] = 0
}
})
return { success: true, counts }
} catch (e) {
console.error('ChatService: 批量获取会话消息总数失败:', e)
return { success: false, error: String(e) }
}
}
/**
* 获取通讯录列表
*/