Skip to main content

Module tree

Module tree 

Source
Expand description

GET /api/v2/pages/tree/ — the site’s page structure, nested.

The flat list endpoint can express a subtree (?descendant_of=) but never its shape: a client building navigation has to fetch every page and reassemble the hierarchy itself. This returns it already nested, localized, and filtered to what the caller may actually see.

§Why it is one query

cms_page.parent_id carries no index — only path, status, url_path and page_type_id do. Asking for each node’s children would therefore be both an N+1 and a sequential scan per node. So this does what auto_menu does: one ORDER BY path fetch (already tree pre-order, index-backed), bucket by parent in memory, then recurse with crate::tree_build. Node count does not change the query count.

§Why it is bounded

MAX_LIMIT = 100 on the list endpoints is a row cap and means nothing to a tree. Without its own ceiling this endpoint is an unbounded response generator, so depth defaults to DEFAULT_DEPTH and the emitted node count is capped at MAX_NODES.

Structs§

TreeQuery

Constants§

DEFAULT_DEPTH
Levels returned when ?depth= is omitted. Deep enough for a primary nav with dropdowns, shallow enough that the default response stays small on a big site.
MAX_DEPTH
Ceiling for ?depth=.
MAX_NODES
Hard cap on emitted nodes, whatever the depth asks for. The response is truncated rather than refused, and meta.truncated says so.

Functions§

tree
GET /api/v2/pages/tree/
tree_inner
Takes a &Pool rather than the Tenant so the whole endpoint is exercisable against an in-memory database — Tenant::for_test needs a real PostgreSQL connection, which would put the restriction-leak test out of reach of the normal suite.