mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-10-29 14:49:36 +08:00
fix(viewer): the routes list's limit counts routes, not one route's calls
The routing manifest has a row per (route, symbol it reaches), and the routes list behind Entry points and the Steps picker folds those rows to one per route. To have rows to fold, it fetched limit * 4 + 1 of them, so an inline handler, which has a row per call in its body, could use up the window by itself, and the routes after it were never fetched. On an Express app with one 24-call inline handler before two routes, limit=3 listed only GET /dense. getRoutingManifest takes a perRoute flag that applies its limit to routes, in the same file and line order, and returns every row of those routes. Without the flag the query and its result are unchanged. Added on top of the contributor's change: the window is still over-fetched, four routes per route shown, because some routes are dropped only after their rows come back (a test or generated handler, an inline route written in a test). A window of exactly limit + 1 routes could hold only those. On hono, whose routes are nearly all registered in test files, Entry points then listed 0 routes instead of main's 28, and the routes list 21 instead of 32. With the over-fetch, every route main lists is still listed at each limit tried (3, 12, 60, 200 and 300), and hono's Entry points list 32. truncated also keeps main's check that the window came back full. Validation: the new limit=3 test fails on main (only GET /dense) and passes here. A project whose test-file routes sort first fails with the PR as first written (it reads as unrouted) and passes here and on main. Routes listed on Wiki.js (132 routes) and realworld-express are identical to main, and on hono they differ only by the additions above. The ui suites and the other route consumers: 34 files, 723 passed, 0 failed, 3 skipped (environment-gated). The changelog line is in docs/viewer-launch-changelog.md, since the viewer is not released yet. Original PR #2370 by @danusha2345. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Colby Mchenry
co-authored by
Claude Opus 5.5
parent
2def0a6d6d
commit
33dc2ae72b
@@ -90,8 +90,13 @@ export function splitRouteName(url: string): { method: string | null; path: stri
|
||||
*/
|
||||
const MIN_LIMIT = 3;
|
||||
|
||||
/** Manifest rows fetched per route shown, so folding repeats still fills the page. */
|
||||
const ROWS_PER_ROUTE = 4;
|
||||
/**
|
||||
* Routes fetched per route shown. Some routes in the window are dropped only
|
||||
* after their rows come back (a test or generated handler, an inline route
|
||||
* written in a test), so the window is over-fetched for them, or a project
|
||||
* whose first routes are its tests' would list few or none of its own.
|
||||
*/
|
||||
const ROUTES_PER_ROUTE_SHOWN = 4;
|
||||
|
||||
type ManifestRow = NonNullable<ReturnType<CodeGraph['getRoutingManifest']>>['entries'][number];
|
||||
|
||||
@@ -143,9 +148,11 @@ export function buildRoutes(cg: CodeGraph, query: URLSearchParams): WireRoutes {
|
||||
// symbols, or an inline handler whose every call reads as a "handler"
|
||||
// (hono's `GET /stream/text` came back three times, as `streamText`,
|
||||
// `writeln` and `sleep`), repeats. A route has ONE answer to "what serves
|
||||
// this" — route-roots.ts's — so rows are over-fetched and folded onto it.
|
||||
const fetched = limit * ROWS_PER_ROUTE + 1;
|
||||
const manifest = cg.getRoutingManifest(fetched);
|
||||
// this" — route-roots.ts's — so every row of a route is fetched and folded
|
||||
// onto it. The window counts routes, not rows: one inline handler with
|
||||
// dozens of calls must not push the routes after it off the page.
|
||||
const fetched = limit * ROUTES_PER_ROUTE_SHOWN + 1;
|
||||
const manifest = cg.getRoutingManifest(fetched, true);
|
||||
const routeCount = cg.getStats().nodesByKind.route ?? 0;
|
||||
|
||||
if (!manifest) {
|
||||
@@ -161,7 +168,7 @@ export function buildRoutes(cg: CodeGraph, query: URLSearchParams): WireRoutes {
|
||||
}
|
||||
|
||||
const folded = oneRowPerRoute(cg, manifest.entries);
|
||||
const truncated = folded.length > limit || manifest.entries.length >= fetched;
|
||||
const truncated = folded.length > limit || new Set(manifest.entries.map((e) => e.routeId)).size >= fetched;
|
||||
const rows = folded.slice(0, limit);
|
||||
|
||||
// Every row's handler file in one batched query, so a project that scatters
|
||||
|
||||
Reference in New Issue
Block a user