Review main Merged

86261[BUGFIX] Fix usages of `RecordIdentityMap`

Oli Bartsch CR +2 V +2 Hard +184 −91 updated 09/28/24, 14:47

Commit message

The RecordIdentityMap is a NOT shared object,
containing already fetched / constructed records.

The map can be used to improve performance by
providing a context-specific, in-memory cache
to prevent duplicate retrieval of the same object
data from the database.

This patch therefore fixes the following issues:

1. RecordFactory does now use a provided identity map
   for fetching records and also stores them in the
   given map, after resolving.

2. The `BackendLayoutRenderer` wrapper already fetches
   records and stores them in the identity map. However,
   the FluidBasedContentPreviewRenderer did previously not
   check the map and fetched the records a second time.
   This is now fixed, leading to less queries on rendering
   the  page module.

3. RecordFieldTransformer does no longer wrongly inject
   the map but requires calling code to provide the map
   in the main `transformField()` method to keep the context.

4. The RecordFactory does now properly provide the map
   when transforming record field values (see #3).

5. The PageContentFetchingProcessor does now properly
   provide the map to the RecordCollector again (this
   has falsely been removed in #103581)

Review

  • Code review CR +2 Done
    • Oli Bartsch +2
    • Jochen Roth +1
    • Benni Mack +1
  • Verified V +2 Done
    • Oli Bartsch +2
    • Jochen Roth +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 8

Review log 2431

Show 46 earlier messages
  1. Oli Bartsch uploaded patch set 1 09/23/24, 07:53

  2. core-ci voted on patch set 1 V -1 09/23/24, 08:01 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66419

  3. Oli Bartsch uploaded patch set 2 V -1 09/23/24, 08:06

  4. core-ci voted on patch set 2 V +1 09/23/24, 08:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66420

  5. Andreas Kienast commented on patch set 2 09/23/24, 08:15

    PageContentFetchingProcessor.php:56

    In the commit message you state that `RecordIdentityMap` is not a shared object, still you inject it now via DI.
  6. Andreas Kienast commented on patch set 2 09/23/24, 08:16

    PageContentFetchingProcessor.php:56 Reply

    If this is inevitable, you may add ``` TYPO3\CMS\Core\Domain\Persistence\RecordIdentityMap: shared: false ``` to `typo3/sysext/core/Configuration/Services.yaml`
  1. Benjamin Franzke commented on patch set 2 09/23/24, 08:34

    FluidBasedContentPreviewRenderer.php:99

    So this is basically a cache around `RecordFactory::createResolvedRecordFromDatabaseRow`. Can be build that into `RecordFactory::createResolvedRecordFromDatabaseRow` (and maybe name it `RecordFactory::getResolvedRecordFromDatabaseRow`)?
  2. Benni Mack commented on patch set 2 09/23/24, 08:59

    FluidBasedContentPreviewRenderer.php:99 Reply

    It's not a cache, as you could have different IdentityMaps based on Contextual settings. You want to dictate from the outside (not within the RecordFactory) what kind of record you want to create or if you want to check the IdentityMap first. The IdentityMap is similar to the Session object (Unit of Work) in Extbase, and we had some really painful problems with that, because the UoW does not care about language / workspace overlays.
  3. Benjamin Franzke commented on patch set 2 09/23/24, 09:03

    FluidBasedContentPreviewRenderer.php:99 Reply

    but the patch passes a `RecordIdentityMap` to `createResolvedRecordFromDatabaseRow`, which is used for all relations, but not the object itself? I looks like all context-sensitive settings should apply to the aggregate and to its relations, so the record identity map can be used for the aggregate by the record factory.

    PageContentFetchingProcessor.php:56 Reply

    Please don't inject it at all then (we don't want `shared: false` if possible), rather instantiate via `new`.
  4. Oli Bartsch uploaded patch set 3 V +1 09/23/24, 14:39

  5. Benni Mack commented on patch set 2 09/23/24, 14:41

    FluidBasedContentPreviewRenderer.php:99 Reply

    indeed. the idea for the RecordIdentityMap was the fact that EXT:CB had relations of a tt_content element, which then references to a slider, which then might reference another tt_content element, which then points to the actual original tt_content element again (e.g. CType=shortcut). Maybe we just need to ensure that a) we load existing objects from the RecordIdentityMap b) we get a IdentityMap instance based on the Context object ? Also, one thing to consider is whether we have RawRecord, Record or whatever other RecordInterface objects in the identity map, which is currently not defined / checked.
  6. core-ci voted on patch set 3 V -1 09/23/24, 14:47 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66445

  7. Oli Bartsch uploaded patch set 4 V -1 09/23/24, 15:01

  8. core-ci voted on patch set 4 V +1 09/23/24, 15:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66446

  9. Oli Bartsch commented on patch set 4 09/23/24, 15:09

    FluidBasedContentPreviewRenderer.php:99 Reply

    I updated the patch to have record factory handle the identity map check. IMO due to the fact that the map (to be used) is provided to the factory, the context is implicit and no need to check for the type of record, stored in the map.

    PageContentFetchingProcessor.php:56 Reply

    Done
  10. Benni Mack commented on patch set 4 CR +1 V +1 09/24/24, 07:05

    FluidBasedContentPreviewRenderer.php:99 Reply

    it's OK for me like that.
  11. Andreas Kienast commented on patch set 4 09/24/24, 07:17

    RecordIdentityMap.php:48

    So you want to have this injectable via DI now? If so, why do we have to update PageContentFetchingProcessor then?
  12. Oli Bartsch uploaded patch set 5 CR +1 V +1 09/24/24, 07:23

  13. Oli Bartsch commented on patch set 5 09/24/24, 07:24

    RecordIdentityMap.php:48 Reply

    Good catch, no DI. Removed the config.
  14. core-ci voted on patch set 5 V +1 09/24/24, 07:35 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66478

  15. Simon Schaufelberger commented on patch set 5 09/24/24, 10:28

    RecordCollector.php:65

    this can be simplified with an fn function call. I'll push an update.
  16. Simon Schaufelberger uploaded patch set 6 V +1 09/24/24, 10:29

  17. Simon Schaufelberger commented on patch set 6 09/24/24, 10:30

    RecordCollector.php:65 Reply

    Done
  18. Simon Schaufelberger wrote 09/24/24, 10:31

    Removed cc Simon Schaufelberger.
  19. core-ci voted on patch set 6 V +1 09/24/24, 10:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66487

  20. Oli Bartsch uploaded patch set 7 V +1 09/25/24, 14:58

  21. core-ci voted on patch set 7 V +1 09/25/24, 15:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66598

  22. Benni Mack voted on patch set 7 CR +1 V +1 09/25/24, 20:52

  23. Jochen Roth voted on patch set 7 CR +1 V +1 09/28/24, 10:21

  24. Oli Bartsch voted on patch set 7 CR +2 V +2 09/28/24, 14:47

  25. Oli Bartsch merged patch set 8 09/28/24, 14:47