Review main Merged

73834[TASK] Re-implement costly regex part of cropHTML programmatically

Nikita Hovratov CR +2 V +2 Expert +960 −189 updated 10/14/22, 06:33

Commit message

The magic happening for cropHTML in the regex is
really hard to understand. It led to compilation
failures due to the costly regex pattern applied on
possibly long pieces of text.

In order to replace the "maxCroppingLength"
workaround, where the regex is applied multiple
times with less text, a new implementation is now
in place.

The new implementation extracts the regex part for
html entities to be used as a straight pattern. This
circumvents the bottleneck of the "entity|."
alternative match for everything.

The remaining logic is implemented in a programmatic
way, which is easy to follow from top to bottom with
added comments.

Functionality of `crop()` is moved to new core class
`\TYPO3\CMS\Core\Text\TextCropper` and `cropHTML()`
methods is moved to corresponding new core class
`\TYPO3\CMS\Core\Html\HtmlCropper` with a modernized
method signature. Old internal ContentObjectRenderer
methods are kept as wrapper methods to properly prepare
argument preparation.

Additionally new `HtmlCropper` and `TextCropper` are
conditionally used in the well known fluid viewhelper
`\TYPO3\CMS\Fluid\ViewHelpers\Format\CropViewHelper`.

MultiByte position calculation error for `TextCropper`
is fixed along the way which bubble up using the html
crop tests from `ContentObjectRenderer` also for the
`TextCropper`.

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
    • Nikita Hovratov +1
  • Verified V +2 Done
    • Stefan Bürk +2
    • Nikita Hovratov +1
    • core-ci +1 CI

Issues 2

Files 7

Review log 3147

Show 1322 earlier messages
  1. Nikita Hovratov uploaded patch set 1 03/07/22, 07:27

  2. core-ci voted on patch set 1 V +1 03/07/22, 07:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/24649

  3. Stefan Bürk rebased onto patch set 2 07/08/22, 21:26

  4. Benni Mack commented on patch set 2 07/08/22, 21:34

    I highly suggest to move this (now that we tackle this) to EXT:core/Classes/Html/HtmlCropper.php with a ->crop() method. This method is internal and has ZERO dependencies :)
  5. Stefan Bürk commented on patch set 2 CR -1 07/08/22, 21:36

    Reply

    Ack. Will look into this tomorrow. Thanks for the suggestions.
  6. core-ci voted on patch set 2 V -1 07/08/22, 21:40 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28784

  7. core-ci voted on patch set 2 V +1 07/08/22, 21:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28784

  8. Stefan Bürk uploaded patch set 3 07/09/22, 21:24

  9. Stefan Bürk commented on patch set 3 07/09/22, 21:28

    Reply

    ContentObjectRenderer->crop() and cropHTML() are used in corresponding stdWrap_crop() and stdWrap_cropHtml() methods. Additionally the CropViewHelper has instanciated a ContentObjectRenderer object to call both methods directly. @Benni I have "combined" both into the HtmlCropper, with direct method arguments and a additional flag if tags should be respected or not and replaced the usage in the viewhelper also. Switched patch to WIP for now - todo's marked in the commit message for now. Should we move the tests and make the wrappings in ContentObjectRenderer protected ? HtmlCropper internal or public API ?
  10. Stefan Bürk uploaded patch set 4 07/09/22, 21:29

  11. core-ci voted on patch set 3 V -1 07/09/22, 21:34 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28838

  12. core-ci voted on patch set 4 V -1 07/09/22, 21:36 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28839

  13. Stefan Bürk uploaded patch set 5 07/09/22, 21:44

  14. core-ci voted on patch set 5 V +1 07/09/22, 21:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28842

  15. Stefan Bürk uploaded patch set 6 07/30/22, 19:48

  16. core-ci voted on patch set 6 V -1 07/30/22, 19:55 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29724

  17. Stefan Bürk uploaded patch set 7 07/30/22, 21:29

  18. Stefan Bürk updated the commit message in patch set 8 07/30/22, 21:30

  19. Stefan Bürk commented on patch set 8 07/30/22, 21:34

    Reply

    * Splitted ContentObjectRenderer->crop() to TextCropper * Splitted ContentObjectRenderer->cropHTML() to HtmlCropper Both cropper are simple classers without hard dependencies, thus can be used as simply utils. I have "duplicated" the tests from ContentObjectRenderer, which mainly were related to cropHTML() to tests for both croppers (exluding html tag/entities tests for the TextCropper). This also showed up that the "crop()" implementation still had multibyte issues which were undetected due missing tests for it. This is fixed along the way. @Benni Both cropper internal or should we open them as core api / public stuff ?
  20. core-ci voted on patch set 8 V -1 07/30/22, 21:46 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29726

  21. Stefan Bürk uploaded patch set 9 07/30/22, 21:46

  22. core-ci voted on patch set 7 V -1 07/30/22, 21:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29725

  1. core-ci voted on patch set 9 V +1 07/30/22, 21:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29729

  2. Benni Mack commented on patch set 9 08/01/22, 12:21

    Reply

    I think you can remove the internal flag for the new classes, people should use them directly from EXT:core and not have cObj instantiated for this 😊
  3. Simon Schaufelberger commented on patch set 9 08/01/22, 21:52

    TextCropper.php:38

    respecting

    TextCropper.php:39

    I would prefer an early return, otherwise the method is really deeply nested
  4. Oliver Klee commented on patch set 9 08/01/22, 22:16

    TextCropper.php:39 Reply

    We can in addition break up the method into smaller, well-named methods that are then called from crop(). This also would make the methods a lot easier to read and understand.
  5. Stefan Bürk rebased onto patch set 10 08/03/22, 15:57

  6. core-ci voted on patch set 10 V +1 08/03/22, 16:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29797

  7. Simon Schaufelberger rebased onto patch set 11 09/21/22, 23:29

  8. core-ci voted on patch set 11 V +1 09/21/22, 23:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31399

  9. Stefan Bürk uploaded patch set 12 10/13/22, 14:56

  10. core-ci voted on patch set 12 V +1 10/13/22, 15:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32295

  11. Stefan Bürk uploaded patch set 13 10/13/22, 15:05

  12. Stefan Bürk uploaded patch set 14 10/13/22, 15:07

  13. Stefan Bürk commented on patch set 14 10/13/22, 15:11

    Reply

    Removed the @internal flag from both cropper classes. Ack, better getting these cropper classes directly instead of the ContentObjectRenderer.

    TextCropper.php:38 Reply

    Done

    TextCropper.php:39 Reply

    Added early return, which jogged the code a litte bit in shape. However, splitting in methods does not really make pays out here .. has to be kind of multiple methods now one later really can reconize in a quick sense .. It's a small function with every thing in place. Most important - this code is "moved" as a "side change", this patch is about re-implementing the html crop code - and moving it out. So let's not work on a side-war place here without real outcome here. Through the splitting the TextCropper has now a little bit more test coverage, so feel free to play with the balls of this small and convenient method to make it a multi method splitt beast in a dedicated patch.
  14. core-ci voted on patch set 13 V +1 10/13/22, 15:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32296

  15. core-ci voted on patch set 14 V +1 10/13/22, 15:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32297

  16. Stefan Bürk voted on patch set 14 V +1 CR +1 10/13/22, 15:15

  17. Stefan Bürk uploaded patch set 15 10/13/22, 15:19

  18. Stefan Bürk voted on patch set 15 V +1 CR +1 10/13/22, 15:20

  19. Oliver Klee wrote 10/13/22, 15:22

    Removed cc Oliver Klee.
  20. Stefan Bürk voted on patch set 15 CR -1 10/13/22, 15:22

  21. Stefan Bürk voted on patch set 15 CR +1 10/13/22, 15:23

  22. core-ci voted on patch set 15 V +1 10/13/22, 15:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32299

  23. Nikita Hovratov voted on patch set 15 V +1 CR +1 10/13/22, 15:45

  24. Stefan Bürk voted on patch set 15 V +2 CR +2 10/14/22, 06:33

  25. Stefan Bürk merged patch set 16 10/14/22, 06:33