kotti.traversal

This module contains Kotti’s node tree traverser.

In Kotti versions < 1.3.0, Pyramid’s default traverser (pyramid.traversal.ResourceTreeTraverser) was used. This traverser still works, but it becomes decreasingly performant the deeper your resource tree is nested. This is caused by the fact, that it generates one DB query per level, whereas the Kotti traverser (kotti.traversal.NodeTreeTraverser) generates a single DB query, regardless of the number of request path segments. This query not only finds the context, but also returns all node items in its lineage. This means, that neither accessing context.parent nor calling pyramid.location.lineage() will result in additional DB queries.

The performance benefits are huge. The table below compares the requests per seconds (rps) that were reached on a developer’s notebook against a PostgreSQL database with 4419 kotti.resources.Document nodes.

request.path Pyramid traverser (rps) Kotti traverser (rps)
/ 49 49
/a/ 41 36
/a/b/ 30 35
/a/b/c/ 23 34
/a/b/c/d/ 19 33
/a/b/c/d/e/ 16 33
/a/b/c/d/e/f/ 14 33
/a/b/c/d/e/f/g/ 12 32
/a/b/c/d/e/f/g/h/ 11 31
/a/b/c/d/e/f/g/h/i/ 10 30
/a/b/c/d/e/f/g/h/i/j/ 8 29
class kotti.traversal.NodeTreeTraverser(root)[source]

An optimized resource tree traverser for kotti.resources.Node based resource trees.

static traverse(root, vpath_tuple)[source]
Parameters:
  • root (kotti.resources.Node) – The node where traversal should start
  • vpath_tuple (tuple) – Tuple of path segments to be traversed
Returns:

List of nodes, from root (excluded) to context (included). Each node has its parent set already, so that no subsequent queries will be be performed, e.g. when calling lineage(context)

Return type:

list of kotti.resources.Node

kotti.traversal.includeme(config)[source]

Pyramid includeme hook.

Parameters:config (pyramid.config.Configurator) – app config