#111406Find the subpages of a page with one database query
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
-
Gerrit Code Review pushed patch set 1 for main to change 97537 status
NewUnder Review <span data-processor="relativetime" data-value="2026-11-11T11:24:46+00:00" > 11/11/26, 11:24 </span> -
Gerrit Code Review pushed patch set 2 for main to change 97537 <span data-processor="relativetime" data-value="2026-11-11T12:44:06+00:00" > 11/11/26, 12:44 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 97537 <span data-processor="relativetime" data-value="2026-11-11T14:48:11+00:00" > 11/11/26, 14:48 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 97537 <span data-processor="relativetime" data-value="2026-11-11T15:58:20+00:00" > 11/11/26, 15:58 </span>
-
Gerrit Code Review pushed patch set 5 for main to change 97537 <span data-processor="relativetime" data-value="2026-11-15T08:27:52+00:00" > 11/15/26, 08:27 </span>
-
Gerrit Code Review pushed patch set 6 for main to change 97537 <span data-processor="relativetime" data-value="2026-11-19T08:41:06+00:00" > 11/19/26, 08:41 </span>
-
Benni Mack commented and changed status
Under ReviewResolved done0 %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.