From 3b954f21ea5af7767db6e6fdaa1dad87d775cb20 Mon Sep 17 00:00:00 2001 From: Oliver Eglseder Date: Fri, 12 Apr 2024 09:29:38 +0200 Subject: [PATCH] [BUGFIX] Sort the list of categories to reduce the amount of possible combinations Each combination of category uids will result in a different cache hash. This means, that 1,3 and 3,1 are cached separately, although the order does not make a difference for the news listing. Sorting the category uids ensures, that the number of possible combinations is as low as possible. Fixes: #2374 --- .../MultiCategoryLink/ArgumentsViewHelper.php | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/Classes/ViewHelpers/MultiCategoryLink/ArgumentsViewHelper.php b/Classes/ViewHelpers/MultiCategoryLink/ArgumentsViewHelper.php index b48e85e73a..4d72985e28 100644 --- a/Classes/ViewHelpers/MultiCategoryLink/ArgumentsViewHelper.php +++ b/Classes/ViewHelpers/MultiCategoryLink/ArgumentsViewHelper.php @@ -71,17 +71,21 @@ public static function renderStatic( $allArguments = (array)$arguments['additionalParams']; $categoryId = (int)$arguments['item']; - $categoryList = $arguments['list']; + // All IDs are numeric. Hence, split and type cast. + $categoryList = GeneralUtility::intExplode(',', $arguments['list'], true); if ($arguments['mode'] === 'add') { - if (!GeneralUtility::inList($categoryList, $categoryId)) { - $categoryList .= ',' . $categoryId; - } + $categoryList[] = $categoryId; } else { - $categoryList = self::rmFromList($categoryId, $categoryList); + // array_diff has the advantage, that it does not care how often the searched value occurs. + $categoryList = array_diff($categoryList, [$categoryId]); } + // Ensure each ID to only occur once + $categoryList = array_unique($categoryList); + // Sort IDs, so lists are more uniform and less duplicate caches are generated + sort($categoryList); if (!empty($categoryList)) { - $categoryList = trim($categoryList, ','); + $categoryList = implode(',', $categoryList);; $categoryArray = [ 'tx_news_pi1' => [ 'overwriteDemand' => [ @@ -94,15 +98,4 @@ public static function renderStatic( return $allArguments; } - - private static function rmFromList($element, $list) - { - $items = explode(',', $list); - foreach ($items as $k => $v) { - if ($v == $element) { - unset($items[$k]); - } - } - return implode(',', $items); - } }