Issue Feature Resolved

#111406Find the subpages of a page with one database query

Benni Mack 11/11/26, 10:57 updated 11/21/26, 09:40

Description

Several parts of TYPO3 collect the subpages of a page – recursively, down to a given depth – by walking the page tree in PHP with one database query per page. Each of them implements this on its own, with different handling of workspaces, languages and permissions:

  • PageTreeRepository::getFlattenedPages() (record list, live search, belog, suggest wizard)
  • WorkspaceService::getTreeUids() (workspaces module)
  • Extbase BackendConfigurationManager (persistence.recursive of backend modules)
  • QuerySearchController (lowlevel database search)
  • AdministrationRepository (indexed_search)
  • DeletedRecords (recycler)

For a page tree of 780 pages, this means up to 907 queries, and in a workspace additional queries per versioned page.

A new PageDescendantsRepository fetches the descendants of one or more pages with one recursive common table expression (CTE):

  • only pages of the default language, resolved for a workspace: pages moved in the workspace are found at their new position, pages new in the workspace are included, pages deleted in the workspace are left out together with their subpages
  • access restrictions are handed in by the caller: query restrictions evaluated on the workspace version of a page (e.g. hidden), and a constraint evaluated on the live page, e.g. the page permissions of a backend user
  • the result is ordered depth-first by the “sorting” of the pages, with the level of each page, optionally with the full page records

The backend parts listed above use the new repository. Measured with 780 pages: PageTreeRepository::getFlattenedPages() needs 2 instead of 6 queries live and 5 instead of 130 in a workspace, WorkspaceService::getTreeUids() and the Extbase storage pids 1 instead of 907 / 905 queries. Extbase no longer returns the uids of workspace versions as storage pids.

Frontend usages (PageRepository::getDescendantPageIdsRecursive(), with mount points and extendToSubpages) are not changed yet.

Reviews 4

History 17

  1. Benni Mack commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-11-21T09:40:16+00:00" > 11/21/26, 09:40 </span>

    Applied in changeset commit:7a11476afc2d4210dd830292778d0d97e3b5d84b.