feat: implement directory tree read model and API#155
Merged
YusukeHirao merged 3 commits intoJul 3, 2026
Conversation
Add design notes for viewer_directory_nodes/viewer_directory_pages — host-based root_key exclusion rule, trailing-slash directory/page boundary, has_children semantics, and the index-column-order fix (vdn_path_depth) found via EXPLAIN QUERY PLAN.
Add viewer_directory_nodes/viewer_directory_pages tables plus getDirectoryTree/listDirectoryChildren/listDirectoryPages so the viewer can browse the crawled URL space as a directory tree without splitting/counting URL strings at request time (issue #107). - buildDirectoryTreeRows: pure builder reusing buildViewerReadModel's existing sourceRows, no second pages SELECT. Groups nodes by host, excludes hosts with zero internal pages, and resolves the directory/page boundary via trailing slash. - has_children reflects only child directories (not direct pages), since the tree UI only ever expands into subdirectories. - getDirectoryTree/listDirectoryChildren/listDirectoryPages guard on isViewerReadModelCurrent (not just hasViewerReadModel) because this feature has no legacy fallback path. - vdn_path_depth leads with path_sort_key so the depth<=3 filter stays a residual check instead of forcing a temp b-tree sort, verified via EXPLAIN QUERY PLAN. - Bumps VIEWER_READ_MODEL_SCHEMA_VERSION 3 -> 4 to force a rebuild.
Register GET /api/directory-tree, /api/directory-tree/children, and /api/directory-tree/pages, wiring @nitpicker/query's new directory tree functions into the viewer's Hono app (issue #107).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
viewer_directory_nodes/viewer_directory_pagesread-model tables andbuildDirectoryTreeRows(pure builder, reusesbuildViewerReadModel's existingsourceRows, no secondpagesSELECT).getDirectoryTree/listDirectoryChildren/listDirectoryPagesquery functions and wire them into the viewer asGET /api/directory-tree,/api/directory-tree/children,/api/directory-tree/pages.root_keyis host-based, excluding hosts with zero internal pages (avoids pointless single-page trees for external link targets)./blog/2024/post-1and/blog/2024/land on the same node).has_childrenreflects only child directories, not direct pages, matching the tree UI's actual expand affordance.isViewerReadModelCurrent(not justhasViewerReadModel) guards all three query functions, since this feature has no legacy fallback path.vdn_path_depthindex leads withpath_sort_keysogetDirectoryTree'sdepth <= 3filter stays a residual check instead of forcing aTEMP B-TREEsort — verified viaEXPLAIN QUERY PLAN.VIEWER_READ_MODEL_SCHEMA_VERSION3 → 4.Closes #107. Frontend UI is intentionally out of scope (no companion issue existed yet; to be filed separately).
Test plan
yarn test— 2351 passed, 5 skippedyarn lint— 0 errors (eslint/stylelint/markuplint/prettier/textlint/cspell all clean)query/viewer/cli/mcp-serverdirectly viatsc(sandbox'syarn buildsilently no-ops ontsc— verified separately)EXPLAIN QUERY PLANconfirmsvdn_path_depthavoids a temp b-tree sort forgetDirectoryTree's querynodeId400s, and empty response when the read model isn't built🤖 Generated with Claude Code