Skip to main content

Module tree_ops

Module tree_ops 

Source
Expand description

Tree mutation + read API on top of Page.

All operations are dialect-agnostic. Read-only queries accept &rustango::sql::Pool. Write operations that require atomic transactions (create_root, create_child, move_to, cascade_url_path_to_descendants) open a PoolTx via write_transaction(&tenant.pool()) and use the _tx ORM helpers.

Path generation is two-step: the materialized-path segment is the row’s auto-assigned id, which we don’t know until after INSERT. To avoid the brief window where path = "", every create wraps the insert + path update in a transaction.

move_to also takes a transaction because it rewrites every row in the moved subtree atomically.

created_at / updated_at are framework-stamped (auto_now_add / auto_now); callers don’t fill them.

Structs§

NewPage
Builder for the user-supplied fields when creating a page. Tree fields (path, depth, parent_id, sort_order) and timestamps are computed by the create_* helpers — callers don’t fill them.

Enums§

TreeError
Errors from tree operations.

Functions§

atomic_tree
Run f inside a framework rustango::sql::atomic scope while letting it return TreeError — the bridge that lets the on_commit cache-invalidation pattern reach the tree-write paths.
cascade_url_path_to_descendants
Recompute and persist url_path for every descendant of root_page after its own url_path changes.
compute_url_path
Compute the public URL path a page is reachable at, given its parent’s url_path (or None for root) and its own slug. Maintained on every create / slug-change / move.
rebuild_all_url_paths
Recompute url_path for every page in the tenant from scratch. Walks all pages in path order so parents update before children. Useful as a one-shot recovery / backfill verb when external SQL has touched cms_page outside the admin.
validate_child_placement
Check that the (parent_type, child_type) pairing is permitted by both handlers’ whitelists. Skipped when either type’s whitelist is empty (the convention for “no restriction”). Public to make it usable from admin form hooks and other write paths.