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) {
|
||||
|
||||
Reference in New Issue
Block a user