fix: 避免 Reader 有界空窗读取阻塞主线程

This commit is contained in:
hateyouing-ai committed 2026-11-10 15:27:06 +08:00
1 parent 804466aad8
commit 00b55c9cca
5 files changed
+442 -41

No files matched your search

+11 -3
View File
@@ -6,7 +6,7 @@ import {
isReady,
listContacts,
listContactsAsync,
listMessages,
listMessagesAsync,
getGroupSnapshot,
listRecentChat,
resolveMd5,
@@ -433,7 +433,7 @@ const routes: Record<string, RouteHandler> = {
sendJson(res, 200, { count: items.length, items })
}),
'/api/v1/chatlog': withMethods(['GET'], ({ res, url }) => {
'/api/v1/chatlog': withMethods(['GET'], async ({ res, url }) => {
if (!isReady()) return sendError(res, 503, 'TraceMemo 数据库未初始化')
const talker = url.searchParams.get('talker')
if (!talker) return sendError(res, 400, '缺少必要参数 talker')
@@ -462,7 +462,15 @@ const routes: Record<string, RouteHandler> = {
}
}
const messages = listMessages(resolved.md5, startTime, endTime)
// A quiet time window can fall back to a long native history scan. Use the
// asynchronous, time-filtered shard reader so it cannot block /health or the UI.
const messages = await listMessagesAsync(
resolved.md5,
startTime,
endTime,
undefined,
String(res.getHeader('X-Request-Id') || '')
)
sendJson(res, 200, {
contact: resolved,
query: { talker, time: timeParam, startTime, endTime },