perf(wiki): subgraph API and interactive exploration for large graphs
Wikis with tens of thousands of pages used to crash the browser trying to render the entire link graph at once (30MB+ JSON, 100k+ SVG elements). This change moves the graph viewer from "fetch everything, render everything" to "fetch a slice, expand on demand" with several matching UX improvements. Backend * GET /wiki/graph now accepts `mode` (overview | ego), `center`, `depth`, `types`, `limit` query params. Default is overview top-500 by link_count, capped at 2000. Response includes a Meta object so the frontend can render a truncation hint and drive the UI. * Pure helper `computeGraphSubset` extracted for testability; six unit tests cover overview truncation / type filter / ego BFS / missing center error. * WikiLintService passes Limit=0 (uncapped) so link integrity checks still walk every page. * Repo `Search` adds CASE-based relevance ranking (title 4, slug 3, summary 2, content 1) so full-text results put the most obvious matches first instead of whatever was updated most recently. Frontend * Graph viewer fetches overview on entry; ego pivot on double-click, search, wiki-link click, URL ?slug=, global issues jump. * Shift+click or hover ⊕ button blooms neighbors onto the current canvas additively. Bloom tracks generations and LRU-evicts oldest when total exceeds 1500 nodes; ego center / selected node / latest anchor are always protected. * "Grow frontier (N)" legend action expands every dashed-ring node in one click (6-way concurrency) while skipping Index/Log super-nodes that would otherwise dump the whole wiki onto the canvas. * Node dashed expansion ring + drawer "X/Y neighbors shown" hint tell users which nodes still have neighbors to load. * Search dropdown uses remote full-text search (debounced, sequence- numbered to drop stale responses) and falls back to the overview top-500 snapshot when the input is empty. * Type filters now round-trip to the server so top-N is always computed from the user's active type set rather than hiding nodes client-side and shrinking the view. * Status card replaces the cramped "centered on X · N hops · M nodes" line with a structured focus/overview summary, resolving slugs to page titles. * Help popover in the legend lists every canvas shortcut. i18n entries added for zh-CN / en-US / ko-KR / ru-RU.
This commit is contained in:
@@ -37,9 +37,19 @@ export interface WikiPageListResponse {
|
||||
total_pages: number;
|
||||
}
|
||||
|
||||
export interface WikiGraphMeta {
|
||||
mode: 'overview' | 'ego' | string;
|
||||
total: number;
|
||||
returned: number;
|
||||
truncated: boolean;
|
||||
center?: string;
|
||||
depth?: number;
|
||||
}
|
||||
|
||||
export interface WikiGraphData {
|
||||
nodes: { slug: string; title: string; page_type: string; link_count: number }[];
|
||||
edges: { source: string; target: string }[];
|
||||
meta: WikiGraphMeta;
|
||||
}
|
||||
|
||||
export interface WikiStats {
|
||||
@@ -113,8 +123,32 @@ export function getWikiLog(kbId: string) {
|
||||
return get(`/api/v1/knowledgebase/${kbId}/wiki/log`);
|
||||
}
|
||||
|
||||
export function getWikiGraph(kbId: string) {
|
||||
return get(`/api/v1/knowledgebase/${kbId}/wiki/graph`);
|
||||
export interface WikiGraphQueryParams {
|
||||
mode?: 'overview' | 'ego';
|
||||
center?: string;
|
||||
depth?: number;
|
||||
types?: string[];
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
// getWikiGraph fetches a slice of the wiki link graph. Without params the
|
||||
// backend returns the top-500 most-connected pages (overview mode). Pass
|
||||
// `mode: 'ego', center: <slug>` to drill into a specific page's neighborhood.
|
||||
// For knowledge bases with tens of thousands of pages the overview cap is
|
||||
// what prevents the browser from choking on a 30MB payload / 100k SVG nodes.
|
||||
export function getWikiGraph(kbId: string, params?: WikiGraphQueryParams) {
|
||||
const query = new URLSearchParams();
|
||||
if (params) {
|
||||
if (params.mode) query.set('mode', params.mode);
|
||||
if (params.center) query.set('center', params.center);
|
||||
if (params.depth !== undefined) query.set('depth', String(params.depth));
|
||||
if (params.limit !== undefined) query.set('limit', String(params.limit));
|
||||
if (params.types && params.types.length > 0) {
|
||||
query.set('types', params.types.join(','));
|
||||
}
|
||||
}
|
||||
const qs = query.toString();
|
||||
return get(`/api/v1/knowledgebase/${kbId}/wiki/graph${qs ? '?' + qs : ''}`);
|
||||
}
|
||||
|
||||
export function getWikiStats(kbId: string) {
|
||||
|
||||
@@ -1709,6 +1709,38 @@ export default {
|
||||
graphNoData: 'No graph data yet. Upload documents first.',
|
||||
showArrows: 'Show arrows',
|
||||
hideArrows: 'Hide arrows',
|
||||
expandNeighbors: 'Expand neighbors',
|
||||
bloomNeighbors: 'Bloom neighbors',
|
||||
growFrontier: 'Grow frontier ({count})',
|
||||
growFrontierTitle: 'Expand all {count} dashed-ring nodes in one click',
|
||||
cardEgoTitle: 'Current focus',
|
||||
cardOverviewTitle: 'KB overview',
|
||||
cardOverviewPrimary: '{returned} / {total} nodes',
|
||||
cardOverviewHintTruncated: 'Double-click any node to focus on its subgraph',
|
||||
cardOverviewHintFull: 'Showing every node in the knowledge base',
|
||||
cardRelatedNodes: '{count} related nodes',
|
||||
helpButtonTitle: 'Help',
|
||||
helpTitle: 'Canvas actions',
|
||||
helpClickAction: 'Click',
|
||||
helpClickDesc: 'Open node details',
|
||||
helpDblClickAction: 'Double-click',
|
||||
helpDblClickDesc: 'Focus on this node',
|
||||
helpShiftClickAction: 'Shift + click',
|
||||
helpShiftClickDesc: 'Bloom neighbors onto canvas',
|
||||
helpHoverPlusAction: 'Hover → ⊕',
|
||||
helpHoverPlusDesc: 'Same as Shift + click',
|
||||
helpDragAction: 'Drag node',
|
||||
helpDragDesc: 'Reposition the node',
|
||||
helpPanAction: 'Drag empty space',
|
||||
helpPanDesc: 'Pan the canvas',
|
||||
helpZoomAction: 'Scroll wheel',
|
||||
helpZoomDesc: 'Zoom the canvas',
|
||||
neighborsProgress: 'Showing {visible} of {total} neighbors ({hidden} not loaded)',
|
||||
neighborsAllShown: 'All {total} neighbors are already on the canvas (click Expand to focus on this node’s subgraph)',
|
||||
neighborsNone: 'This page has no linked neighbors',
|
||||
neighborsCenterUnreachable: 'Showing {visible} of {total} neighbors ({hidden} unreachable: dead links, filtered, or deleted)',
|
||||
neighborsOverviewHidden: 'Showing {visible} of {total} neighbors ({hidden} outside the overview — click Expand to pivot here)',
|
||||
backToOverview: 'Back to overview',
|
||||
healthCheck: 'Health Check',
|
||||
queueStatus: '{count} pending tasks in Wiki queue',
|
||||
issueTitle: 'This page has {count} pending knowledge conflicts or errors',
|
||||
|
||||
@@ -2321,6 +2321,38 @@ export default {
|
||||
graphNoData: '그래프 데이터가 없습니다. 먼저 문서를 업로드하세요.',
|
||||
showArrows: '화살표 표시',
|
||||
hideArrows: '화살표 숨기기',
|
||||
expandNeighbors: '이웃 확장',
|
||||
bloomNeighbors: '이웃 추가',
|
||||
growFrontier: '경계 확장 ({count})',
|
||||
growFrontierTitle: '점선 링이 있는 {count}개 노드를 한 번에 확장',
|
||||
cardEgoTitle: '현재 초점',
|
||||
cardOverviewTitle: 'KB 개요',
|
||||
cardOverviewPrimary: '{returned} / {total} 개 노드',
|
||||
cardOverviewHintTruncated: '노드를 더블클릭하여 서브그래프에 집중',
|
||||
cardOverviewHintFull: '지식 베이스의 모든 노드 표시 중',
|
||||
cardRelatedNodes: '관련 노드 {count}개',
|
||||
helpButtonTitle: '도움말',
|
||||
helpTitle: '캔버스 작업',
|
||||
helpClickAction: '클릭',
|
||||
helpClickDesc: '노드 상세 보기',
|
||||
helpDblClickAction: '더블클릭',
|
||||
helpDblClickDesc: '이 노드에 집중',
|
||||
helpShiftClickAction: 'Shift + 클릭',
|
||||
helpShiftClickDesc: '이웃을 캔버스에 추가',
|
||||
helpHoverPlusAction: '호버 → ⊕',
|
||||
helpHoverPlusDesc: 'Shift + 클릭과 동일',
|
||||
helpDragAction: '노드 드래그',
|
||||
helpDragDesc: '노드 위치 조정',
|
||||
helpPanAction: '빈 공간 드래그',
|
||||
helpPanDesc: '캔버스 이동',
|
||||
helpZoomAction: '스크롤 휠',
|
||||
helpZoomDesc: '캔버스 확대/축소',
|
||||
neighborsProgress: '이웃 {visible}/{total} 표시됨 ({hidden}개 미로딩)',
|
||||
neighborsAllShown: '모든 {total}개 이웃이 이미 캔버스에 있습니다 (확장을 클릭하여 이 노드의 서브그래프에 집중)',
|
||||
neighborsNone: '이 페이지에는 연결된 이웃이 없습니다',
|
||||
neighborsCenterUnreachable: '이웃 {visible}/{total} 표시됨 ({hidden}개 연결 불가: 끊긴 링크, 필터됨 또는 삭제됨)',
|
||||
neighborsOverviewHidden: '이웃 {visible}/{total} 표시됨 ({hidden}개는 개요 범위 밖 — 확장을 클릭하여 이곳으로 전환)',
|
||||
backToOverview: '개요로 돌아가기',
|
||||
healthCheck: "상태 점검",
|
||||
queueStatus: "Wiki 대기열에 {count}개의 보류 중인 작업",
|
||||
issueTitle: "이 페이지에는 {count}개의 대기 중인 지식 충돌 또는 오류가 있습니다",
|
||||
|
||||
@@ -1931,6 +1931,38 @@ export default {
|
||||
graphNoData: 'Нет данных графа. Сначала загрузите документы.',
|
||||
showArrows: 'Показать стрелки',
|
||||
hideArrows: 'Скрыть стрелки',
|
||||
expandNeighbors: 'Развернуть соседей',
|
||||
bloomNeighbors: 'Добавить соседей',
|
||||
growFrontier: 'Расширить границу ({count})',
|
||||
growFrontierTitle: 'Развернуть все {count} узлов с пунктирным кольцом за один клик',
|
||||
cardEgoTitle: 'Текущий фокус',
|
||||
cardOverviewTitle: 'Обзор БЗ',
|
||||
cardOverviewPrimary: '{returned} / {total} узлов',
|
||||
cardOverviewHintTruncated: 'Дважды щёлкните узел, чтобы сфокусироваться на его подграфе',
|
||||
cardOverviewHintFull: 'Показаны все узлы базы знаний',
|
||||
cardRelatedNodes: '{count} связанных узлов',
|
||||
helpButtonTitle: 'Справка',
|
||||
helpTitle: 'Действия на холсте',
|
||||
helpClickAction: 'Клик',
|
||||
helpClickDesc: 'Открыть детали узла',
|
||||
helpDblClickAction: 'Двойной клик',
|
||||
helpDblClickDesc: 'Сфокусироваться на узле',
|
||||
helpShiftClickAction: 'Shift + клик',
|
||||
helpShiftClickDesc: 'Добавить соседей на холст',
|
||||
helpHoverPlusAction: 'Наведение → ⊕',
|
||||
helpHoverPlusDesc: 'То же, что Shift + клик',
|
||||
helpDragAction: 'Перетащить узел',
|
||||
helpDragDesc: 'Изменить положение узла',
|
||||
helpPanAction: 'Перетащить пустое место',
|
||||
helpPanDesc: 'Переместить холст',
|
||||
helpZoomAction: 'Колесо мыши',
|
||||
helpZoomDesc: 'Масштабировать холст',
|
||||
neighborsProgress: 'Показано {visible} из {total} соседей (еще {hidden} не загружено)',
|
||||
neighborsAllShown: 'Все {total} соседей уже на холсте (нажмите «Развернуть», чтобы сфокусироваться на подграфе этого узла)',
|
||||
neighborsNone: 'У этой страницы нет связанных соседей',
|
||||
neighborsCenterUnreachable: 'Показано {visible} из {total} соседей ({hidden} недоступны: мёртвые ссылки, отфильтрованы или удалены)',
|
||||
neighborsOverviewHidden: 'Показано {visible} из {total} соседей ({hidden} вне обзора — нажмите «Развернуть», чтобы переключиться сюда)',
|
||||
backToOverview: 'Вернуться к обзору',
|
||||
healthCheck: 'Проверка здоровья',
|
||||
queueStatus: '{count} ожидающих задач в очереди Wiki',
|
||||
issueTitle: 'На этой странице есть {count} неразрешенных конфликтов или ошибок знаний',
|
||||
|
||||
@@ -2292,6 +2292,38 @@ export default {
|
||||
graphNoData: '暂无图谱数据,请先上传文档',
|
||||
showArrows: '显示箭头',
|
||||
hideArrows: '隐藏箭头',
|
||||
expandNeighbors: '展开邻居',
|
||||
bloomNeighbors: '叠加邻居',
|
||||
growFrontier: '扩张边缘 ({count})',
|
||||
growFrontierTitle: '一键展开当前所有 {count} 个带虚线环的节点',
|
||||
cardEgoTitle: '当前焦点',
|
||||
cardOverviewTitle: '全库概览',
|
||||
cardOverviewPrimary: '{returned} / {total} 个节点',
|
||||
cardOverviewHintTruncated: '双击任意节点聚焦到该节点的子图',
|
||||
cardOverviewHintFull: '已展示知识库全部节点',
|
||||
cardRelatedNodes: '{count} 个相关节点',
|
||||
helpButtonTitle: '操作帮助',
|
||||
helpTitle: '画布操作',
|
||||
helpClickAction: '单击',
|
||||
helpClickDesc: '打开节点详情',
|
||||
helpDblClickAction: '双击',
|
||||
helpDblClickDesc: '以该节点为中心聚焦',
|
||||
helpShiftClickAction: 'Shift + 单击',
|
||||
helpShiftClickDesc: '叠加该节点邻居到画布',
|
||||
helpHoverPlusAction: '悬浮 → ⊕',
|
||||
helpHoverPlusDesc: '同 Shift + 单击',
|
||||
helpDragAction: '拖拽节点',
|
||||
helpDragDesc: '手动调整节点位置',
|
||||
helpPanAction: '拖拽空白',
|
||||
helpPanDesc: '平移画布',
|
||||
helpZoomAction: '滚轮',
|
||||
helpZoomDesc: '缩放画布',
|
||||
neighborsProgress: '已显示邻居 {visible}/{total}(还有 {hidden} 个未加载)',
|
||||
neighborsAllShown: '全部 {total} 个邻居已在图中(可点"展开邻居"聚焦到该节点子图)',
|
||||
neighborsNone: '该节点没有链接邻居',
|
||||
neighborsCenterUnreachable: '已显示邻居 {visible}/{total}(还有 {hidden} 个无法连通:可能是死链、被过滤或已删除)',
|
||||
neighborsOverviewHidden: '已显示邻居 {visible}/{total}({hidden} 个不在概览范围,点"展开邻居"以此为中心查看)',
|
||||
backToOverview: '返回概览',
|
||||
healthCheck: "健康检查",
|
||||
queueStatus: "Wiki 队列中 {count} 个待处理任务",
|
||||
issueTitle: "此页面存在 {count} 个待处理的知识冲突或错误",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user