#89058PageRouter::matchRequest could use a cache
Description
Currently, on every request PageRouter::matchRequest collects all slug candidates and chooses the best candidate. Depending on the amount of records in the database, this may lead to a lot of queries.
For a route that has been resolved previously, the result might get cached for faster resolving. This needs a proper concept in terms of cache invalidation.
Reviews 1
Related issues 1
Files 4
History 1519
-
Christian Eßl changed category <span data-processor="relativetime" data-value="2019-10-01T20:40:33+00:00" > 10/01/19, 20:40 </span>
-
Benni Mack changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2019-11-04T09:45:43+00:00" > 11/04/19, 09:45 </span> -
Carlos Meyer commented <span data-processor="relativetime" data-value="2019-11-11T17:04:15+00:00" > 11/11/19, 17:04 </span>
We have the performance problem currently in an installation with 1600 domains too. In our case we fixed it by extending the query in the getPagesFromDatabaseForCandidates, so that only the pages of the current rootline are returned. But I’m not sure if there could be problems with mountpoints?
Changes in PageRouter.php line 334 and below
/** * Get all uids below given page uid * * @param $pageUID * @return string */ private function getRecursivePageUIDs($pageUID) { $depth = 999999; $queryGenerator = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\QueryGenerator'); $rGetTreeList = $queryGenerator->getTreeList($pageUID, $depth, 0, 1); //Will be a string return explode(',', $rGetTreeList); } /** * Check for records in the database which matches one of the slug candidates. * * @param array $slugCandidates * @param int $languageId * @return array */ protected function getPagesFromDatabaseForCandidates(array $slugCandidates, int $languageId): array { $context = GeneralUtility::makeInstance(Context::class); $searchLiveRecordsOnly = $context->getPropertyFromAspect('workspace', 'isLive'); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) ->getQueryBuilderForTable('pages'); $queryBuilder ->getRestrictions() ->removeAll() ->add(GeneralUtility::makeInstance(DeletedRestriction::class)) ->add(GeneralUtility::makeInstance(FrontendWorkspaceRestriction::class, null, null, $searchLiveRecordsOnly)); //restrict query to sites in rootline $uids = $this->getRecursivePageUIDs($this->site->getRootPageId()); $statement = $queryBuilder ->select('uid', 'l10n_parent', 'pid', 'slug') ->from('pages') ->where( $queryBuilder->expr()->in('uid',$uids), $queryBuilder->expr()->eq( 'sys_language_uid', $queryBuilder->createNamedParameter($languageId, \PDO::PARAM_INT) ), $queryBuilder->expr()->in( 'slug', $queryBuilder->createNamedParameter( $slugCandidates, Connection::PARAM_STR_ARRAY ) ) ) // Exact match will be first, that's important ->orderBy('slug', 'desc') ->execute(); -
Carlos Meyer changed attached PageRouter.patch <span data-processor="relativetime" data-value="2019-11-12T16:24:38+00:00" > 11/12/19, 16:24 </span>
-
Carlos Meyer commented <span data-processor="relativetime" data-value="2019-11-13T14:08:24+00:00" > 11/13/19, 14:08 </span>
Please use this patch source: https://raw.githubusercontent.com/protos1575/PageRouter.patch/master/PageRouter.patch
-
Susanne Moog changed Sprint Focus On Location Sprint <span data-processor="relativetime" data-value="2020-01-12T12:46:14+00:00" > 01/12/20, 12:46 </span>
-
Yohann CERDAN commented <span data-processor="relativetime" data-value="2020-02-05T10:20:29+00:00" > 02/05/20, 10:20 </span>
Same problem here, we have a large website with 100+ domains and some mountpoints.
The method getPagesFromDatabaseForCandidates() iterate a lot of non necessary pages (/home/about-us/offices/,/home/about-us/,/home/,/ for each site) and call a lot of methods for each.
For examples, in my case, i will iterate overs 500+ pages to find the slug that appear in the first row of the query. This result in a big performance issue.So, even if we find a page wich are on the same site, we iterate all the others pages.
If we have the good site ID and the exact same slug, maybe we could stop iteration here? -
Xavier Perseguers commented and changed attached typo3-core-speedup-slug-resolution-with-many-sites.patch <span data-processor="relativetime" data-value="2023-04-13T08:28:17+00:00" > 04/13/23, 08:28 </span>
Just investigated this problem this morning and indeed, I implemented a simple cache which tremendously speeds up all my websites. This is day and night!
From my Slack investigations (https://typo3.slack.com/archives/C025BQLFA/p1681370066698969):
- Around 300 domains in the install
- Using mount point for shared pages (such as the authentication page which is the same for every site)
- Resolving the candidates for/share/authenticationfor a given domain takes around 3.5 sec (locally, needs to loop over 600+ rows)
- Resolving the root page such as/frfor a given domain takes around 1.6 sec.
- Using the simple cache I did then only takes a few ms (!!!)Please see patch as attachement.
I’m using a cache for a custom extension that automatically flushes the caches based on modified table name + uid by hooking into DataHandler, that’s why I think I can safely use a 90 day cache validity and I generate tags of the form
pages%UID -
Xavier Perseguers commented <span data-processor="relativetime" data-value="2023-04-13T08:53:06+00:00" > 04/13/23, 08:53 </span>
After adapting the original patch from @protos as provided in #89058-6 to work with current TYPO3 v10, it turns out this does not work at all to restrict the query on the subpages of a given site when you work with mount points.
Too bad indeed, I liked the idea even though the very first call was then much longer to complete since it had to compute the full page tree of my domain once.
So I’ll go back to my caching solution for the time being.
-
Xavier Perseguers commented and changed attached typo3-core-89058-speed-up-slug-resolution-with-many-sites.patch <span data-processor="relativetime" data-value="2023-04-13T09:44:11+00:00" > 04/13/23, 09:44 </span>
Please find enclosed (
typo3-core-89058-speed-up-slug-resolution-with-many-sites.patch) a generic solution that doesn’t rely on my own caching mechanism. -
Christian Eßl changed Related to #95690 <span data-processor="relativetime" data-value="2023-04-13T10:29:17+00:00" > 04/13/23, 10:29 </span>
-
Benni Mack changed Sprint Focus
On Location Sprint<span data-processor="relativetime" data-value="2023-08-02T12:32:09+00:00" > 08/02/23, 12:32 </span> -
Xavier Perseguers commented and changed attached typo3-core-89058-speed-up-slug-resolution-with-many-sites_v2.patch <span data-processor="relativetime" data-value="2025-06-20T12:17:17+00:00" > 06/20/25, 12:17 </span>
tracked down a bug where “anonymous result sets” could pollute the cache and prevent some legit page localization from working (would result in a 404 when trying to access a translation because the translated page record would not be present in the [wrong] cache entry. Problem spotted and fixed in TYPO3 v11.
-
Benni Mack changed status
Needs FeedbackAccepted <span data-processor="relativetime" data-value="2025-06-21T14:53:19+00:00" > 06/21/25, 14:53 </span> -
Gerrit Code Review pushed patch set 1 for main to change 95753 status
AcceptedUnder Review <span data-processor="relativetime" data-value="2026-09-09T21:55:04+00:00" > 09/09/26, 21:55 </span> -
Gerrit Code Review pushed patch set 2 for main to change 95753 <span data-processor="relativetime" data-value="2026-09-11T17:02:36+00:00" > 09/11/26, 17:02 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 95753 <span data-processor="relativetime" data-value="2026-09-11T17:20:48+00:00" > 09/11/26, 17:20 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 95753 <span data-processor="relativetime" data-value="2026-10-23T13:43:47+00:00" > 10/23/26, 13:43 </span>
Hey Andy,
where exactly are the multiple DB queries located?
AFAIK getPagesFromDatabaseForCandidates() does only one query per language. If workspaces are enabled, we have more, of course.