Skip to main content

Module resolver

Module resolver 

Source
Expand description

URL → Page resolution.

Two paths:

  1. Materialized url_path short-circuit. The request URL is normalized (strip trailing slash unless root) and looked up directly via WHERE url_path = ? — one query regardless of tree depth. The url_path column is indexed and maintained by tree_ops on every create / move / slug change.

  2. Slug-walk fallback for cases the materialized lookup misses — historical rows from before slice 1, draft-preview routes, etc. Walks the slug chain one level at a time and filters to the public statuses.

Both paths serve the public statuses — published and archived (superseded-but-preserved content). Drafts, scheduled, and expired (takedown) rows stay invisible to anonymous visitors. The caller reads page.status to distinguish the two served states.

Functions§

canonical_request_path
Normalize a request path into the canonical form stored in cms_page.url_path. Leading slash kept; trailing slash stripped for non-root URLs. Empty / missing path collapses to /. Exposed for the router’s cache-key builder.
resolve_by_url_path
Look up the page matching url_path directly. One indexed SELECT. Returns Ok(None) when the row is missing OR isn’t public (published / archived). The caller reads page.status to tell the two apart.
resolve_by_walk
Walk the URL path one slug at a time. Used as a fallback when the materialized url_path lookup misses (legacy rows, preview routes, etc.) and for the per-segment ancestry queries that rendered content depends on.
resolve_path
Resolve a request URL to a Page. Tries the materialized url_path first (one query); falls back to the slug walk when no row is found that way (legacy data, in-flight backfills, etc.).
resolve_routable
When resolve_path misses, walk ancestor prefixes of request_path looking for a Page whose registered PageTypeHandler::routes() accepts the remaining suffix. Returns the matched page + match details on first hit (longest prefix wins because crate::routable::ancestor_prefixes orders from most-specific to root).
served_statuses
Statuses a public page can have. archived joins published; scheduled is included only so a page whose go-live time has passed is served before the sweep flips it — visible_now decides. expired is excluded so takedown still 404s. Owned Strings for the is_in binds.
visible_now
Whether a page is public at now, judged by its dates rather than by whether the schedule sweep has run yet: a scheduled page goes live at go_live_at, a published one comes down at expire_at.