77896[TASK] Streamline TSFE::addCacheTags
Commit message
Review
-
Code review CR 0
-
Verified V 0
Issues 1
Files 1
Review log 2836
Show 811 earlier messages
-
Sybille Peters uploaded patch set 1 02/19/23, 10:44
-
Sybille Peters updated the commit message in patch set 2 02/19/23, 10:47
-
Sybille Peters uploaded patch set 3 02/19/23, 10:49
-
Oliver Klee commented on patch set 3 02/19/23, 11:08
Looks very good! I've added comments regarding making the new type annotation more specific.TypoScriptFrontendController.php:466We can be even more specific with list<string> (which means that the array keys are continuous int keys starting with 0).TypoScriptFrontendController.php:1941list<string>TypoScriptFrontendController.php:1960list<string> -
Sybille Peters commented on patch set 3 02/19/23, 11:21
TypoScriptFrontendController.php:466ReplyHmm, can we be sure this is always the case (with the continuous int)? In case an entry is removed in between, probably not. I think it should not be the case here but not 100% sure at this stage what array_merge and array_unique might do. So unless we are sure, I'd rather not change that. It would also help if I could run phpstan locally (which I cannot do currently, it hangs. I will try again and ask for help if not). -
Oliver Klee commented on patch set 3 02/19/23, 11:45
TypoScriptFrontendController.php:466ReplyI could not find any code that removes any element from this array, only adding via on of these three ways: - `$this->pageCacheTags[] = …` - `$this->pageCacheTags = array_merge($this->pageCacheTags, …);` (just tested it: it will re-create the array keys even is `$this->pageCacheTags` is empty) - `$this->pageCacheTags = array_unique($this->pageCacheTags);` So we can be sure that `$this->pageCacheTags` will have 0-based, continuous int keys here. -
core-ci voted on patch set 3 V +1 02/19/23, 11:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37872
-
core-ci voted on patch set 2 V +1 02/19/23, 11:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37871
-
core-ci voted on patch set 1 V +1 02/19/23, 11:55 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37870
-
Sybille Peters uploaded patch set 4
V +102/19/23, 13:26 -
Sybille Peters commented on patch set 4 02/19/23, 13:26
TypoScriptFrontendController.php:466ReplyDoneTypoScriptFrontendController.php:1941ReplyDoneTypoScriptFrontendController.php:1960ReplyDone
-
core-ci voted on patch set 4 V +1 02/19/23, 13:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37877
-
Oliver Klee commented on patch set 4 02/19/23, 14:05
TypoScriptFrontendController.php:1954in_array in most cases should use the strict check: if (!in_array($tag, $this->pageCacheTags, true)) { (Sorry I missed this the first time.) -
Sybille Peters uploaded patch set 5
V +102/19/23, 15:58 -
Sybille Peters commented on patch set 5 02/19/23, 15:59
TypoScriptFrontendController.php:1954ReplyThanks 😊 -
Oliver Klee voted on patch set 5 CR +1 02/19/23, 16:02
-
core-ci voted on patch set 5 V +1 02/19/23, 16:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37881
-
Christian Futterlieb commented on patch set 5 02/20/23, 07:52
TypoScriptFrontendController.php:466ReplyThis solution does not enforce the numeric indexing from zero. If $tags contains an array with string keys for example, they would be preserved through array_merge and array_unique. The same applies to numeric indexed $tags arrays, that do not start with zero. Using array_values will do what you want: $this->pageCacheTags = array_merge($this->pageCacheTags, array_values($tags)); -
Christian Futterlieb commented on patch set 5 02/20/23, 07:56
TypoScriptFrontendController.php:466Reply> The same applies to numeric indexed $tags arrays, that do not start with zero. This part is wrong, my bad. But the problem with the string-indexed $tags remains -
Sybille Peters commented on patch set 5 02/20/23, 08:47
TypoScriptFrontendController.php:466Reply@Christian Futterlieb What are you suggesting then? My take is : I would change the type back to string[]. But I am a bit at a loss what is current practice and would wait for other comments here. If this is called with an array with string keys, a warning will be issued via phpstan if an extension uses phpans and can be changed in the extension: TSFE->addCacheTags(array_value($tags)); For this patch it is not strictly necessary to enforce the stronger types via the PHPDocs. I do however think it is generally a good idea to have stronger types because it self-documents what values are expected and eases checks with phpstan. But, it is done as PHPDoc - so it won't break if a an array with string keys is passed. We could change it to array<int|string,string>, but I think that is worse than before because it implicitly suggest string keys are welcome here. For the functionality currently it is completely irrelevant what the keys are. -
Sybille Peters commented on patch set 5 02/20/23, 08:54
TypoScriptFrontendController.php:466ReplyAbout the suggestion to use : $this->pageCacheTags = array_merge($this->pageCacheTags, array_values($tags)); in addCacheTags (if I understand it correctly): I don't think this is necessary or a good idea to do this in addCacheTags: both arrays are tagged as list<int> (or string [] before the last change) via PHPDoc - so at that point in the function I expect the type to (already) be correct. That would be the responsibility of the calling function and phpstan will call it out. If something should be array_values'd - it should be done BEFORE calling the function. However, if this is done anywhere in the core - we should change it back. But I expected phpstan would have could that. I hope my explanation is understandable and plausible. -
Oliver Klee commented on patch set 5 02/20/23, 15:58
TypoScriptFrontendController.php:466ReplyAh, I see. I indeed missed the case of $tags having string keys. Then the solution with array_values sounds like the right one to me, and addCacheTages should have one of these three @param annotations (all three are semantically identical): - string[] - array<string> - array<string|int, string> -
Sybille Peters uploaded patch set 6
CR +1V +102/20/23, 16:12 -
Sybille Peters commented on patch set 6 02/20/23, 16:17
TypoScriptFrontendController.php:466ReplyDone -
core-ci voted on patch set 6 V +1 02/20/23, 16:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37902
-
Sybille Peters uploaded patch set 7
V +102/20/23, 16:57 -
core-ci voted on patch set 7 V +1 02/20/23, 17:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37903
-
Sybille Peters commented on patch set 7 02/20/23, 17:06
Oli and I talked: We now allow for array keys of int or string when accepting tags from "the outside" but internally, it is always converted into an int array. So in the class property $pageCacheTags and with getPageCacheTags we use list<string>. -
Oliver Klee voted on patch set 7 CR +1 02/20/23, 17:14
-
Christian Futterlieb commented on patch set 7 02/20/23, 18:34
Reply
Great, that's exactly what I meant :)TypoScriptFrontendController.php:1945Since the discussion is about streamlining the type handling, it could be worth it to change this nested array-juggling to something like the following solution. To ensure not only the correct indexing, but also have a 'free' type-check on the values in the $tags array: foreach ($tags as $tag) { $this->addCacheTag($tag); } What do you think? -
Sybille Peters uploaded patch set 8
CR +1V +102/21/23, 16:55 -
Oliver Klee voted on patch set 8 CR +1 02/21/23, 16:57
-
core-ci voted on patch set 8 V +1 02/21/23, 17:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37936
-
Christian Kuhn commented on patch set 8 CR -1 02/22/23, 10:36
TypoScriptFrontendController.php:1945Replyplease no new public methods in tsfe: imho, the entire cache data stuff should be extracted to a request attribute object instead. if this is the way to go, adding new public methods to tsfe which deal with it, add headaches when following this path, so i'd love to avoid this. -
Sybille Peters commented on patch set 8 02/22/23, 11:31
TypoScriptFrontendController.php:1945Reply UnresolvedOk, but this patch does not add a new public function. It modifies an already existing public funtion addCacheTags and adds a protected function addCacheTag. That might be relevant for discussions about the other patch https://review.typo3.org/c/Packages/TYPO3.CMS/+/77894 But the latest variant with the event would avoid having to use public functions even for the cache tags. -
Sybille Peters abandoned the change 02/24/23, 15:58
Refactoring planned "entire cache data should be extracted from tsfe and moved to a request attribute." so approach does not make that much sense now or should be postponed.