Review main Abandoned

74442[BUGFIX] Clear page cache after file replaced

Simon Schaufelberger CR 0 V -1 Normal +126 −0 updated 03/07/26, 19:25

Commit message

Review

  • Code review CR 0
  • Verified V -1
    • core-ci -1 CI

Issues 3

Files 2

Review log 2229

Show 34 earlier messages
  1. Simon Schaufelberger uploaded patch set 1 04/27/22, 00:03

  2. Simon Schaufelberger uploaded patch set 2 04/27/22, 00:06

  3. Simon Schaufelberger commented on patch set 2 04/27/22, 00:15

    I was looking for some APIs in the core to get the references but the only solution right now is to copy the code from several other places which is really not nice. Otherwise the EventListener could just be calling a method to get the references and then clear the page cache for all these references. Done.
  4. core-ci voted on patch set 1 V +1 04/27/22, 00:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26487

  1. core-ci voted on patch set 2 V +1 04/27/22, 00:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26488

  2. Simon Schaufelberger updated the commit message in patch set 3 04/27/22, 00:17

  3. Simon Schaufelberger uploaded patch set 4 04/27/22, 00:20

  4. core-ci voted on patch set 3 V +1 04/27/22, 00:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26489

  5. Simon Schaufelberger commented on patch set 4 04/27/22, 00:29

    Unresolved

    Open for discussion: - References API? - Name and folder of EventListener? - Tests? What should they cover? - Where else does the page cache need to get deleted?
  6. core-ci voted on patch set 4 V +1 04/27/22, 00:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26490

  7. Simon Schaufelberger uploaded patch set 5 04/30/22, 21:11

  8. Simon Schaufelberger commented on patch set 5 04/30/22, 21:12

    In a next step the added methods in the EventListener could be extracted into \TYPO3\CMS\Core\Database\ReferenceIndex and create a nice API for it, but that would be a new FEATURE, so this is out of scope.
  9. core-ci voted on patch set 5 V +1 04/30/22, 21:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26706

  10. Stefan Bürk commented on patch set 5 04/30/22, 22:00

    Reply

    FYI: ReferenceIndex is fully internal. It is no public api eitherway. ``` * @internal Extensions shouldn't fiddle with the reference index themselves, it's task of DataHandler to do this. ``` However, is using a event really the best way to handle this "bug" ? In the end, if there is missing clearing of caches after something has changed, this should directly be fixed where it happens - before calling any hook/event for it. But maybe I'm missing the point or the full context here. Not sure if this approach is the correct one - but I think I simply do not get the point of it (yet). A file replace, which triggers this event, uses the FileIndexRepository before to update the file index, and with it the reference index. And triggering another event afterwards. See: https://github.com/TYPO3/typo3/blob/6f7514f51634fd98a4d4def818c3f16e28aff538/typo3/sysext/core/Classes/Resource/Index/FileIndexRepository.php#L400 Which then calls the ReferenceIndex to update it. Using a "later" event, to call than reference index seems kind of a long workaround instead of fixing an issue. Do you think, the problem or the way to fix maybe reinvestigated ?
  11. Simon Schaufelberger commented on patch set 5 04/30/22, 23:05

    Reply Unresolved

    My idea was separation of concerns as a repository should not necessarily also do other stuff than dealing with the persistence only. Clearing page caches is not the responsibility of a repository, or? That is why I came up with using the event.
  12. Oliver Klee commented on patch set 5 05/01/22, 08:55

    AfterFileReplacedEventListener.php:27

    Please let’s have a short description for this class: Why is exists, and/or how to use it.

    AfterFileReplacedEventListener.php:33

    typo: clea -> clear

    AfterFileReplacedEventListener.php:35 Unresolved

    Why the annotation? (If $file could be null or something else, I propose we check that and throw an exception instead of silencing the problem using an annotation.)

    AfterFileReplacedEventListener.php:50

    @return array<int, int>

    AfterFileReplacedEventListener.php:97

    Please let’s have an @return annotation with details about the array for the benefit of human readers and static code analysis: @return array{recuid: int, tablename: string}
  13. Simon Schaufelberger commented on patch set 5 05/04/22, 12:04

    I had a call with Stefan about this topic and it seams much more complex than just clearing the caches where an image is referenced as I totally overlooked that images can also be referenced in a reference content object on another page for example and then the internal reference index doesn't know about this other page. So currently it is only a half solution.
  14. Simon Schaufelberger marked it work in progress 06/09/22, 16:11

  15. Simon Schaufelberger uploaded patch set 6 V +1 10/24/23, 11:17

  16. Simon Schaufelberger uploaded patch set 7 10/24/23, 11:19

  17. Simon Schaufelberger commented on patch set 7 10/24/23, 11:20

    AfterFileReplacedEventListener.php:33 Reply

    Done

    AfterFileReplacedEventListener.php:50 Reply

    Done

    AfterFileReplacedEventListener.php:97 Reply

    Done
  18. core-ci voted on patch set 6 V -1 10/24/23, 11:28 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48122

  19. core-ci voted on patch set 7 V -1 10/24/23, 11:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48123

  20. Georg Ringer commented on patch set 7 10/24/23, 13:24

    This change is ready for review.
    what about having it as a feature ?

    AfterFileReplacedEventListener.php:49 Unresolved

    shouldn't that be called something like getReferencedPageIds
  21. Benni Mack commented on patch set 7 10/24/23, 15:03

    AfterFileReplacedEventListener.php:27 Reply

    I would recommend calling the class listener to actually what it does ("PageCacheForReplacedFileFlusher" or something like that). In addition, we could use __invoke instead of "public function clearPageCache"
  22. Simon Schaufelberger commented on patch set 7 10/24/23, 18:02

    Reply Unresolved

    Oha, why do people start giving reviews suddenly because I marked it as WIP? The big problem I already wrote down is that it only partially works because I had a call with Stefan about this topic and it seams much more complex than just clearing the caches where an image is referenced as I totally overlooked that images can also be referenced in a reference content object on another page for example and then the internal reference index doesn't know about this other page. So currently it is only a half solution.

    AfterFileReplacedEventListener.php:27 Reply Unresolved

    Thank you for looking into this Patch but I marked it as WIP as there is still a lot to be done, see comments above.
  23. Simon Schaufelberger marked it work in progress 10/24/23, 18:02

  24. Andy Meier commented on patch set 7 04/08/24, 13:59

    Unresolved

    Stumbled across these issues upon backporting the patch to 11.5.

    AfterFileReplacedEventListener.php:76 Unresolved

    the column of the sys_file_reference row is named `tablenames` not `tablename`. Renaming the variable to ``` $recordReference = $this->transformFileReferenceToRecordReference($row); ``` would prevent this confusion.

    AfterFileReplacedEventListener.php:81 Unresolved

    `$recordReference['tablename']`

    AfterFileReplacedEventListener.php:103 Unresolved

    `'tablenames'`

    AfterFileReplacedEventListener.php:116 Unresolved

    `$fileReference['tablenames']`

    Services.yaml:223 Unresolved

    Typo. Change to `'clearPageCache'`
  25. Simon Schaufelberger abandoned the change 03/07/26, 19:25