Review main Abandoned

81390[TASK] Keep SiteFinder and SiteConfiguration in sync

Christoph Lehmann CR 0 V 0 Normal +75 −0 updated 11/10/26, 10:35

Commit message

Due to their multi-level caching architecture they might be out of sync.
This is the case when you

1. Instantiate SiteFinder
2. Instantiate SiteConfiguration and add new Site
3. SiteFinder->findSiteByRootpageId() doesn't find the new Site

With this, their state is synced.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 3

Review log 1318

  1. Christoph Lehmann uploaded patch set 1 10/09/23, 18:04

  2. Christoph Lehmann uploaded patch set 2 10/09/23, 18:07

  3. Oliver Klee commented on patch set 2 10/09/23, 18:08

    The issue ID is missing. Is this change still WIP?
  4. core-ci voted on patch set 1 V -1 10/09/23, 18:14 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47612

  5. Christoph Lehmann uploaded patch set 3 10/09/23, 18:16

  6. core-ci voted on patch set 2 V -1 10/09/23, 18:20 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47613

  7. Christoph Lehmann updated the commit message in patch set 4 10/09/23, 18:20

  8. Christoph Lehmann updated the commit message in patch set 5 10/09/23, 18:27

  9. Christoph Lehmann commented on patch set 5 10/09/23, 18:30

    Reply

    Done
  10. core-ci voted on patch set 3 V +1 10/09/23, 18:31 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47615

  11. core-ci voted on patch set 4 V +1 10/09/23, 18:31 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47616

  12. core-ci voted on patch set 5 V +1 10/09/23, 18:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47618

  13. Stefan Bürk commented on patch set 5 10/11/23, 23:16

    Thank you for this patch. However, from my side adding additional information to control this somehow they way around looks now even more hackish then before. Not to offend you, but I want to express that it would be better to nail this down in another way and also resolving some other things which kind of smells. Let me explain: `SiteConfiguration` is the class dealing with the real files, the code cache for the parsed yaml files. That means it's bound to cache clear things and rebuilds. That makes this class "stateless", which is a really good thing. And it's the internal implementation. `SiteFinder` is the documented way to work with and find proper SiteConfigurations in different places through the core and also for extension authors. It fetches information by using a bound SiteConfiguration instance - using the code cache effectly or rebuild the information on the fly. The retrieved data is not directly suitable for the the SiteFinder and splitted into two array as state on the instance (which is a singleton). That means, that after something changed in a request the cached data in the `SiteFinder` is stalled. Maybe this is neglitable in BE or FE WebRequests, but can be extremly anoying in tests or CLI commands and imports or things like that - or for migrations/ deployment scenarious. The pain point are the `$sites` and `$mappingRootPageIdToIdentifier` property caches. These are filled on creating the SiteFinder object. You tried to have kind of a way to "sync" that now down. Thinking about that, I would disagree here to add additional state / value on both classes ($this->cacheTime) to connect that. Beside this still leaves paths open where data may still be stalled. Thinking about that - I would do following: Move the $sites/$mappingRootPageIdToIdentifier caches, which are just splitted information to the `SiteConfiguration` class. Either as property caches there or by using a additional RuntimeCache instance. Than, we can clear the specific runtime cache along with the code cache on writeOperations. And directly rebuilding the $sites/$mappingRootPageIdToIdentifier cache when the yaml stuff is written or read on cold caches. Therefore, I would remove the `SiteFinder->fetchAllSites()` method and add two simple dispatch methods `getSitesCache()` and `getRootPageToIdentifierMapping()` on both classes. The SiteFinder calls the pair method on bound instance `$this->siteConfiguration`. For example, `SiteFinder->getSiteByRootPageId()` ```php // before: public function getSiteByRootPageId(int $rootPageId): Site { if (isset($this->mappingRootPageIdToIdentifier[$rootPageId])) { return $this->sites[$this->mappingRootPageIdToIdentifier[$rootPageId]]; } throw new SiteNotFoundException( 'No site found for root page id ' . $rootPageId, 1521668882 ); } // after: public function getSiteByRootPageId(int $rootPageId): Site { if (isset($this->getRootPageToIdentifierMapping()[$rootPageId])) { return $this->getSitesCache()[$this->getRootPageToIdentifierMapping()[$rootPageId]]; } throw new SiteNotFoundException( 'No site found for root page id ' . $rootPageId, 1521668882 ); } ``` but dropping the property caches. No need to check some timestamp. And having a property. At least as a roughly picture - in detail there are some more stuff to do. Adding a runTime cache to SiteConfiguration may be easier doable because the @internal mark then the SiteFinder. An other but similar way would be to have a runtime cache injected in both classes, and communication by using the same "key" in some way - or at least removing it on a write in the SiteConfiguration. What do you think ?
  14. Christoph Lehmann commented on patch set 5 11/01/23, 22:19

    Reply Unresolved

    Thanks for review. Good point with the additional state. Using the runtimeCache really sounds like a better solution. Will adapt.
  15. Christoph Lehmann marked it work in progress 11/01/23, 22:19

  16. Oliver Hader updated the commit message in patch set 6 V +1 10/18/24, 14:09

  17. Benni Mack commented on patch set 6 11/10/26, 10:35

    Superseded by #105264 (https://review.typo3.org/c/Packages/TYPO3.CMS/+/86548, "Stateless SiteFinder", in main and 13.4.0+). It moves the root-page mapping into the runtime cache, which is cleared on SiteConfigurationChangedEvent, as Stefan suggested. #102131 is closed. Abandoning, and thanks for the initial work, Christoph!
  18. Benni Mack abandoned the change 11/10/26, 10:35