Review main Abandoned

78024[TASK] Improve performance of PageLinkBuilder on single-site setups

Christian Eßl CR 0 V 0 Easy +4 −1 updated 01/07/25, 14:08

Commit message

When generating a link with the PageLinkBuilder, for routing, the site,
the target page belongs to, needs to be fetched with
$siteFinder->getSiteByPageId() first. Internally, the SiteFinder then
needs to newly fetch the rootline starting from the target page's id,
to safely know, which Site the page belongs to. On pages with many
links, this would lead to many db requests, because for every single new
page id, a new rootline has to be fetched.

At least on single-site setups, this can safely be skipped by passing
the already present rootline from $tsfe->rootline, saving many
superfluous db requests.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 1

Review log 3240

Show 1215 earlier messages
  1. Christian Eßl uploaded patch set 1 03/04/23, 12:15

  2. core-ci voted on patch set 1 V -1 03/04/23, 13:23 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38436

  3. Stefan Bürk commented on patch set 1 03/04/23, 13:36

    Missing `Releases` line ...
  4. Simon Schaufelberger commented on patch set 1 03/04/23, 13:42

    PageLinkBuilder.php:101

    if this is still so resource intensive on multidomain sites, wouldn't it make sense to introduce a runtime cache here to fetch it only once for one request or am I misunderstanding something here?
  5. Christoph Lehmann commented on patch set 1 03/05/23, 09:23

    Reusing the current rootline looks wrong to me. I think you need the target rootline anyway, because, how would you evaluate if its not hidden by a page in the rootline with hidden=1 and extendToSubpages=1 ?

    PageLinkBuilder.php:101 Reply

    The Rootline Utility has its own cache.
  6. Benni Mack commented on patch set 1 03/06/23, 09:01

    PageLinkBuilder.php:101 Reply

    Hey Christian, I recommend doing it like this: https://github.com/plan2net/single-site
  7. Christian Eßl commented on patch set 1 03/06/23, 15:33

    PageLinkBuilder.php:101 Reply

    Hm, I thought about that as well, but I'm not sure. For instance, BackendUtility::getPreviewUrl() calls getSiteByPageId() with a rootline from backend context. If it does not a find a page with the rootline, it will throw a SiteNotFoundException. What if I try to build a preview uri from a separate page tree, that no site (yet?) attached? Then it would falsely return the site of another page tree.
  8. Benni Mack commented on patch set 1 03/06/23, 16:39

    PageLinkBuilder.php:101 Reply

    this ain't possible anymore in v10+ (except if you manually delete a config/sites folder in the file system), however, I would never support a case where a person expects the BE to work if someone manually deleted files. This is only possible if e.g. you still have dangling pages/records somewhere around, or if you are on pid=0 AFAIK
  9. Christian Eßl commented on patch set 1 03/06/23, 17:08

    PageLinkBuilder.php:101 Reply

    What about this: The SiteResolver middleware in the backend calls siteMatcher->matchByPageId(), which itself calls getSiteByPageId(). When I now create a sysfolder on root level, this root folder wouldn't have an auto-generated site. The SiteResolver middleware then expects a NullSite in this case. With your proposed solution it would falsely receive the site of the other page tree. From what I see, this middleware even creates NullSites outside of the page tree with pageuid = 0 and then expects a NullSite. In that scenario we also would get wrong results.
  10. Christian Eßl rebased onto patch set 2 V -1 03/07/23, 20:30

  11. core-ci voted on patch set 2 V -1 03/07/23, 21:34 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38627

  12. Christian Eßl commented on patch set 2 03/08/23, 06:56

    PageLinkBuilder.php:101 Reply

    Hm, I don't really understand, why only some of the functional tests fail in this regard and suddenly create a sole uri instead of a tagged link: https://git.typo3.org/typo3/CI/cms/-/jobs/2048531 TYPO3 works in mysterious ways. My guess: Because of the problems in the nature of tests with static states and I skip the fetching of the Rootline, if only one site exists, in _some_ cases, the tests will have a weird rootline state, that messes up the link building?!
  13. Christian Eßl commented on patch set 2 03/08/23, 07:00

    PageLinkBuilder.php:101 Reply

    Maybe there is still another rootline in cache from a previous test, that messes up the link building of this test.
  14. Christian Eßl uploaded patch set 3 V -1 03/08/23, 07:47

  15. core-ci voted on patch set 3 V -1 03/08/23, 08:53 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38639

  1. Christian Eßl uploaded patch set 4 V -1 03/08/23, 09:32

  2. core-ci voted on patch set 4 V -1 03/08/23, 11:12 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38648

  3. Christian Eßl uploaded patch set 5 V -1 03/08/23, 19:09

  4. core-ci voted on patch set 5 V +1 03/08/23, 19:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38667

  5. Georg Ringer voted on patch set 5 CR +1 03/08/23, 19:30

  6. Christian Eßl commented on patch set 5 03/08/23, 19:33

    The weird test failures are now fixed. Turned out an additional check, that $tsfe->rootline is not an empty array, was missing. But im still unsure about your suggestion @Benni, because of the reasons stated above.

    PageLinkBuilder.php:101 Reply

    Done
  7. Christoph Lehmann voted on patch set 5 V +1 CR +1 03/08/23, 20:07

  8. Christoph Lehmann commented on patch set 5 03/08/23, 20:17

    Reply

    Done
  9. Oliver Klee updated the commit message in patch set 6 CR +1 V +1 03/08/23, 20:30

  10. Oliver Klee commented on patch set 6 03/08/23, 20:30

    Reply

    Done
  11. core-ci voted on patch set 6 V +1 03/08/23, 20:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38668

  12. Josef Glatz updated the commit message in patch set 7 V +1 09/07/23, 20:58

  13. core-ci voted on patch set 7 V -1 09/07/23, 21:06 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/46361

  14. Oliver Klee commented on patch set 7 10/08/23, 13:24

    How should we proceed here?
  15. Benni Mack rebased onto patch set 8 V -1 10/23/23, 08:15

  16. Benni Mack commented on patch set 8 10/23/23, 08:15

    let's get it in :)
  17. core-ci voted on patch set 8 V +1 10/23/23, 08:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48069

  18. Oliver Klee commented on patch set 8 10/23/23, 09:00

    PageLinkBuilder.php:101 Unresolved

    I propose switching the first two conditions to have the cheaper condition first: ```php $rootLine = ($tsfe->rootLine !== [] && count($siteFinder->getAllSites()) === 1) ? $tsfe->rootLine : null; ```
  19. Stefan Bürk commented on patch set 8 CR -1 10/23/23, 09:14

    Unresolved

    -1 because the assumption this change is based on is wrong. See comment of the commit message. Should be -2 eventually as I could not think about how to fix that while keeping the simplyfication. But leaving it as -1, maybe someone else has a solution for it.
    This assumption is wrong. For example, it is possible to have one site configuration / tree root, but also having a `system folder` on the root level and pages beneath it. It normal sub page under the system folder is linked somewhere, this page should not be linked. With this patch, this link is now rendered using the site configuration from the wrong tree branch. The assumption even in the commentar in the code that a site configuration should be there every where is basically wrong - until now. ``` root +--> site-root(config) | +--> page 1 | +--> system folder +--> page 2 ``` If now, for example on page 1 a text element is placed and a link created to `page` the current behaviour is to not generate that link (because that branch does not have a site configuration). With this change, the siteconfig from "site-root" is used and a link generated using that base information. The problem is, that the generated link can be clicked - but not resolved. Therefore, it's a invalid link. This simplification opens up to a invalid link generation, therefore we cannot do that. Cannot think about a solution to simplyfy this here without having this caveat - at least for now.
  20. Stefan Bürk commented on patch set 8 10/23/23, 09:32

    Reply Unresolved

    Note: The issue is, that if a rootline is provided the rootline is simply parsed down to the the site config, there is no additional check if the pageId is in that rootline. So that could be the solution - the rootline check in getSiteByPageId() needs to check if the pageId is in the rootline. That this may be okay.
  21. Oliver Klee wrote 08/25/24, 10:12

    Removed cc Oliver Klee.
  22. Benni Mack updated the commit message in patch set 9 CR -1 V +1 10/18/24, 13:46

  23. Benni Mack commented on patch set 9 12/19/24, 19:07

    unless there is activity (see Stefan's comments) I suggest to close this change.
  24. Christian Kuhn commented on patch set 9 01/07/25, 14:08

    as suggested by benni, i'm going to abandon here for now.
  25. Christian Kuhn abandoned the change 01/07/25, 14:08