chore: 收口 review 执行清单与 runtime 验证
- 补齐 design/10-review 执行清单、验收标准与相关设计治理记录 - 迁移已完成的 tree、mindmap、runtime fallback、AI kernel 等设计和缺陷条目 - 推进 Rust Web runtime、tree/sidebar、page aggregate、mindmap 与 OnlyOffice 路由侧验证支撑 - 增加 task177-task180 smoke/audit 脚本及前端相关测试覆盖
This commit is contained in:
@@ -38,6 +38,10 @@ function decodeCursor(raw: string | null | undefined) {
|
||||
}
|
||||
}
|
||||
|
||||
function stripDomainEventCursorPrefix(id: string) {
|
||||
return id.startsWith("domain_event:") ? id.slice("domain_event:".length) : id;
|
||||
}
|
||||
|
||||
function encodeCursor(row: { created_at?: string | null; id?: string | null } | null) {
|
||||
if (!row?.created_at || !row?.id) return null;
|
||||
return JSON.stringify({
|
||||
@@ -46,6 +50,25 @@ function encodeCursor(row: { created_at?: string | null; id?: string | null } |
|
||||
});
|
||||
}
|
||||
|
||||
function encodeDomainEventCursor(row: { created_at?: string | null; id?: string | null } | null) {
|
||||
if (!row?.created_at || !row?.id) return null;
|
||||
return JSON.stringify({
|
||||
createdAt: row.created_at,
|
||||
id: `domain_event:${row.id}`,
|
||||
});
|
||||
}
|
||||
|
||||
function encodeOverviewNextCursor(
|
||||
commandLogs: Array<{ created_at?: string | null; id?: string | null }>,
|
||||
domainEvents: Array<{ created_at?: string | null; id?: string | null }>,
|
||||
) {
|
||||
// overview 的分页主轴仍以 command log 为准;没有 command log 时才回退到 domain event cursor。
|
||||
// 实时流的 live tail 每轮查最新窗口,不依赖这个 next_cursor。
|
||||
const oldestCommand = commandLogs[commandLogs.length - 1] ?? null;
|
||||
const oldestEvent = domainEvents[domainEvents.length - 1] ?? null;
|
||||
return encodeCursor(oldestCommand) ?? encodeDomainEventCursor(oldestEvent);
|
||||
}
|
||||
|
||||
function matchesCursor<T extends Record<string, any>>(
|
||||
row: T,
|
||||
cursor: { createdAt: string; id: string } | null,
|
||||
@@ -53,10 +76,11 @@ function matchesCursor<T extends Record<string, any>>(
|
||||
if (!cursor) return true;
|
||||
const createdAt = String(row.created_at ?? row.finished_at ?? "");
|
||||
const id = String(row.id ?? "");
|
||||
const cursorId = stripDomainEventCursorPrefix(cursor.id);
|
||||
if (!createdAt || !id) return false;
|
||||
if (createdAt < cursor.createdAt) return true;
|
||||
if (createdAt > cursor.createdAt) return false;
|
||||
return id < cursor.id;
|
||||
return id < cursorId;
|
||||
}
|
||||
|
||||
function normalizeStatusFilter(raw: string | null | undefined) {
|
||||
@@ -69,6 +93,128 @@ function normalizeObjectFilter(raw: string | null | undefined) {
|
||||
return normalized.length > 0 ? normalized : null;
|
||||
}
|
||||
|
||||
type Cursor = { createdAt: string; id: string } | null;
|
||||
|
||||
const OVERVIEW_SCAN_MULTIPLIER = 4;
|
||||
|
||||
function overviewScanLimit(limit: number) {
|
||||
return Math.min(500, Math.max(limit + 1, limit * OVERVIEW_SCAN_MULTIPLIER));
|
||||
}
|
||||
|
||||
function applyCursorUpperBound(query: any, cursor: Cursor) {
|
||||
return cursor ? query.lte("created_at", cursor.createdAt) : query;
|
||||
}
|
||||
|
||||
async function fetchCommandLogWindow(ctx: any, args: {
|
||||
workspaceId: string;
|
||||
limit: number;
|
||||
cursor: Cursor;
|
||||
commandStatus: string | null;
|
||||
targetPageId: string | null;
|
||||
targetBlockId: string | null;
|
||||
}) {
|
||||
const scanLimit = overviewScanLimit(args.limit);
|
||||
let query;
|
||||
if (args.targetBlockId) {
|
||||
query = ctx.db
|
||||
.query("command_logs")
|
||||
.withIndex("by_workspace_target_block_created_at", (q: any) =>
|
||||
applyCursorUpperBound(
|
||||
q.eq("workspace_id", args.workspaceId).eq("target_block_id", args.targetBlockId),
|
||||
args.cursor,
|
||||
),
|
||||
);
|
||||
} else if (args.targetPageId) {
|
||||
query = ctx.db
|
||||
.query("command_logs")
|
||||
.withIndex("by_workspace_target_page_created_at", (q: any) =>
|
||||
applyCursorUpperBound(
|
||||
q.eq("workspace_id", args.workspaceId).eq("target_page_id", args.targetPageId),
|
||||
args.cursor,
|
||||
),
|
||||
);
|
||||
} else if (args.commandStatus) {
|
||||
query = ctx.db
|
||||
.query("command_logs")
|
||||
.withIndex("by_workspace_status_created_at", (q: any) =>
|
||||
applyCursorUpperBound(
|
||||
q.eq("workspace_id", args.workspaceId).eq("status", args.commandStatus),
|
||||
args.cursor,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
query = ctx.db
|
||||
.query("command_logs")
|
||||
.withIndex("by_workspace_created_at", (q: any) =>
|
||||
applyCursorUpperBound(q.eq("workspace_id", args.workspaceId), args.cursor),
|
||||
);
|
||||
}
|
||||
|
||||
const rows = await query.order("desc").take(scanLimit);
|
||||
const filteredRows = rows.filter((row: any) => {
|
||||
if (args.commandStatus && row.status !== args.commandStatus) return false;
|
||||
if (args.targetPageId && String(row.target_page_id ?? "") !== args.targetPageId) return false;
|
||||
if (args.targetBlockId && String(row.target_block_id ?? "") !== args.targetBlockId) return false;
|
||||
return matchesCursor(row, args.cursor);
|
||||
});
|
||||
return {
|
||||
rows: filteredRows.slice(0, args.limit),
|
||||
hasMore: filteredRows.length > args.limit || rows.length === scanLimit,
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchDomainEventWindow(ctx: any, args: {
|
||||
workspaceId: string;
|
||||
limit: number;
|
||||
cursor: Cursor;
|
||||
eventStatus: string | null;
|
||||
aggregateType: string | null;
|
||||
aggregateId: string | null;
|
||||
}) {
|
||||
const scanLimit = overviewScanLimit(args.limit);
|
||||
let query;
|
||||
if (args.aggregateType && args.aggregateId) {
|
||||
query = ctx.db
|
||||
.query("domain_events")
|
||||
.withIndex("by_workspace_aggregate_created_at", (q: any) =>
|
||||
applyCursorUpperBound(
|
||||
q
|
||||
.eq("workspace_id", args.workspaceId)
|
||||
.eq("aggregate_type", args.aggregateType)
|
||||
.eq("aggregate_id", args.aggregateId),
|
||||
args.cursor,
|
||||
),
|
||||
);
|
||||
} else if (args.eventStatus) {
|
||||
query = ctx.db
|
||||
.query("domain_events")
|
||||
.withIndex("by_workspace_status_created_at", (q: any) =>
|
||||
applyCursorUpperBound(
|
||||
q.eq("workspace_id", args.workspaceId).eq("status", args.eventStatus),
|
||||
args.cursor,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
query = ctx.db
|
||||
.query("domain_events")
|
||||
.withIndex("by_workspace_created_at", (q: any) =>
|
||||
applyCursorUpperBound(q.eq("workspace_id", args.workspaceId), args.cursor),
|
||||
);
|
||||
}
|
||||
|
||||
const rows = await query.order("desc").take(scanLimit);
|
||||
const filteredRows = rows.filter((row: any) => {
|
||||
if (args.eventStatus && row.status !== args.eventStatus) return false;
|
||||
if (args.aggregateType && String(row.aggregate_type ?? "") !== args.aggregateType) return false;
|
||||
if (args.aggregateId && String(row.aggregate_id ?? "") !== args.aggregateId) return false;
|
||||
return matchesCursor(row, args.cursor);
|
||||
});
|
||||
return {
|
||||
rows: filteredRows.slice(0, args.limit),
|
||||
hasMore: filteredRows.length > args.limit || rows.length === scanLimit,
|
||||
};
|
||||
}
|
||||
|
||||
export const recordCommandLog = mutation({
|
||||
args: {
|
||||
workspaceId: v.string(),
|
||||
@@ -280,44 +426,33 @@ export const listWorkspaceOverview = query({
|
||||
const aggregateType = normalizeObjectFilter(args.aggregateType);
|
||||
const aggregateId = normalizeObjectFilter(args.aggregateId);
|
||||
|
||||
const allCommandLogs = await ctx.db
|
||||
.query("command_logs")
|
||||
.withIndex("by_workspace_request", (q) => q.eq("workspace_id", args.workspaceId))
|
||||
.collect();
|
||||
const allDomainEvents = await ctx.db
|
||||
.query("domain_events")
|
||||
.withIndex("by_workspace_request", (q) => q.eq("workspace_id", args.workspaceId))
|
||||
.collect();
|
||||
const commandWindow = await fetchCommandLogWindow(ctx, {
|
||||
workspaceId: args.workspaceId,
|
||||
limit,
|
||||
cursor,
|
||||
commandStatus,
|
||||
targetPageId,
|
||||
targetBlockId,
|
||||
});
|
||||
const domainEventWindow = await fetchDomainEventWindow(ctx, {
|
||||
workspaceId: args.workspaceId,
|
||||
limit,
|
||||
cursor,
|
||||
eventStatus,
|
||||
aggregateType,
|
||||
aggregateId,
|
||||
});
|
||||
|
||||
const filteredCommandLogs = sortByNewest(
|
||||
allCommandLogs.filter((row: any) => {
|
||||
if (commandStatus && row.status !== commandStatus) return false;
|
||||
if (targetPageId && String(row.target_page_id ?? "") !== targetPageId) return false;
|
||||
if (targetBlockId && String(row.target_block_id ?? "") !== targetBlockId) return false;
|
||||
return matchesCursor(row, cursor);
|
||||
}),
|
||||
);
|
||||
|
||||
const pageCommandLogs = filteredCommandLogs.slice(0, limit);
|
||||
const nextCursor = encodeCursor(pageCommandLogs[pageCommandLogs.length - 1] ?? null);
|
||||
const commandIds = new Set(pageCommandLogs.map((row: any) => String(row.command_id)));
|
||||
|
||||
const domainEvents = sortByNewest(
|
||||
allDomainEvents.filter((row: any) => {
|
||||
if (commandIds.size > 0 && !commandIds.has(String(row.command_id ?? ""))) return false;
|
||||
if (eventStatus && row.status !== eventStatus) return false;
|
||||
if (aggregateType && String(row.aggregate_type ?? "") !== aggregateType) return false;
|
||||
if (aggregateId && String(row.aggregate_id ?? "") !== aggregateId) return false;
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
const pageCommandLogs = sortByNewest(commandWindow.rows);
|
||||
const domainEvents = sortByNewest(domainEventWindow.rows);
|
||||
const nextCursor = encodeOverviewNextCursor(pageCommandLogs, domainEvents);
|
||||
|
||||
return {
|
||||
workspace_id: args.workspaceId,
|
||||
command_logs: pageCommandLogs,
|
||||
domain_events: domainEvents,
|
||||
next_cursor: nextCursor,
|
||||
has_more: filteredCommandLogs.length > pageCommandLogs.length,
|
||||
has_more: commandWindow.hasMore || domainEventWindow.hasMore,
|
||||
filters: {
|
||||
command_status: commandStatus,
|
||||
event_status: eventStatus,
|
||||
|
||||
@@ -474,7 +474,11 @@ export default defineSchema({
|
||||
.index("by_command_log_id", ["id"])
|
||||
.index("by_workspace_request", ["workspace_id", "request_id"])
|
||||
.index("by_workspace_trace", ["workspace_id", "trace_id"])
|
||||
.index("by_workspace_command", ["workspace_id", "command_id"]),
|
||||
.index("by_workspace_command", ["workspace_id", "command_id"])
|
||||
.index("by_workspace_created_at", ["workspace_id", "created_at", "id"])
|
||||
.index("by_workspace_status_created_at", ["workspace_id", "status", "created_at", "id"])
|
||||
.index("by_workspace_target_page_created_at", ["workspace_id", "target_page_id", "created_at", "id"])
|
||||
.index("by_workspace_target_block_created_at", ["workspace_id", "target_block_id", "created_at", "id"]),
|
||||
|
||||
domain_events: defineTable({
|
||||
id: v.string(),
|
||||
@@ -495,5 +499,14 @@ export default defineSchema({
|
||||
.index("by_domain_event_id", ["id"])
|
||||
.index("by_workspace_request", ["workspace_id", "request_id"])
|
||||
.index("by_workspace_trace", ["workspace_id", "trace_id"])
|
||||
.index("by_workspace_command", ["workspace_id", "command_id"]),
|
||||
.index("by_workspace_command", ["workspace_id", "command_id"])
|
||||
.index("by_workspace_created_at", ["workspace_id", "created_at", "id"])
|
||||
.index("by_workspace_status_created_at", ["workspace_id", "status", "created_at", "id"])
|
||||
.index("by_workspace_aggregate_created_at", [
|
||||
"workspace_id",
|
||||
"aggregate_type",
|
||||
"aggregate_id",
|
||||
"created_at",
|
||||
"id",
|
||||
]),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user