Query for content sorted by path and position in parent

How can I iterate over content in a portal in exactly the order it appears to Users?

portal_catalog(sort_on=["path", "getObjPositionInParent"]) does not help because getObjPositionInParent is never used because the id of the object is in the path.

The only ideas I have right now:

  1. Add a custom index parent_path and do portal_catalog(sort_on=["parent_path", "getObjPositionInParent"]).

  2. Instead of doing one query do a query for each container somehow using the index is_folderish and path:

  3. Walk the tree instead of using a catalog-query.

If you need to process the complete content, walk it (not using the catalog at all).
Otherwise, locate the content via a catalog search and perform the sorting externally (based on parent_path and getObjPositionInParent).

Plone Foundation Code of Conduct