fix: reduce workbench read model load (#1829)
This commit is contained in:
@@ -23,6 +23,7 @@ const MAX_PAGE_LIMIT = 100;
|
||||
const DEFAULT_WORKBENCH_SSE_HEARTBEAT_MS = 15000;
|
||||
const WORKBENCH_SESSION_LIST_PAGE_FAMILIES = Object.freeze(["sessions"]);
|
||||
const WORKBENCH_SESSION_DETAIL_FAMILIES = Object.freeze(["sessions", "messages", "parts", "turns", "checkpoints"]);
|
||||
const WORKBENCH_SESSION_MESSAGE_PAGE_FAMILIES = Object.freeze(["sessions", "messages", "parts"]);
|
||||
const WORKBENCH_TRACE_EVENT_METADATA_FAMILIES = Object.freeze(["sessions", "messages", "turns", "checkpoints"]);
|
||||
const WORKBENCH_TRACE_EVENT_PAGE_FAMILIES = Object.freeze(["traceEvents"]);
|
||||
export async function handleWorkbenchReadModelHttp(request, response, url, options = {}) {
|
||||
@@ -486,7 +487,7 @@ async function queryFactsForSessionSummaries(readModel, sessions = []) {
|
||||
const traceIds = uniqueText(sessions.map(factLastTraceId));
|
||||
if (sessionIds.length === 0 && traceIds.length === 0) return { facts: emptyFactSet(), count: 0, durable: false, persistence: null };
|
||||
const bySessionPromise = sessionIds.length > 0
|
||||
? readModel.queryFacts({ sessionIds, families: ["messages", "parts", "turns"] })
|
||||
? readModel.queryFacts({ sessionIds, families: ["messages", "turns"] })
|
||||
: Promise.resolve({ facts: emptyFactSet(), count: 0, durable: false, persistence: null });
|
||||
const byTracePromise = traceIds.length > 0
|
||||
? readModel.queryFacts({ traceIds, families: ["checkpoints"] })
|
||||
@@ -1057,7 +1058,7 @@ async function handleWorkbenchSessionDetail(response, options, actor, sessionId)
|
||||
|
||||
async function handleWorkbenchMessagePage(response, url, options, actor, sessionId) {
|
||||
const readModel = createWorkbenchReadModel(options, actor);
|
||||
const result = await queryFactsByRouteId(readModel, sessionId, { families: WORKBENCH_SESSION_DETAIL_FAMILIES });
|
||||
const result = await queryFactsByRouteId(readModel, sessionId, { families: WORKBENCH_SESSION_MESSAGE_PAGE_FAMILIES });
|
||||
if (result.error) return sendJson(response, 503, workbenchProjectionStoreError(result.error));
|
||||
const session = visibleFactSessions(result.facts, actor)[0] ?? null;
|
||||
if (!session) return sendJson(response, 404, workbenchError("workbench_session_not_found", "Workbench session is not visible to the current actor.", { sessionId }));
|
||||
@@ -1094,7 +1095,7 @@ async function handleWorkbenchTurnSnapshot(response, url, options, actor, rawTur
|
||||
return sendJson(response, 400, body);
|
||||
}
|
||||
const readModel = createWorkbenchReadModel(options, actor);
|
||||
const result = await readModel.queryFacts({ traceId, limit: MAX_PAGE_LIMIT });
|
||||
const result = await readModel.queryFacts({ traceId, limit: MAX_PAGE_LIMIT, families: WORKBENCH_TRACE_EVENT_METADATA_FAMILIES });
|
||||
if (result.error) {
|
||||
const body = workbenchProjectionStoreError(result.error);
|
||||
recordWorkbenchTurnReadMetric(options, url, 503, body, startedAt);
|
||||
|
||||
Reference in New Issue
Block a user