From 67c402a37a157f8f8e520dcaa848bc9b6ef4db7d Mon Sep 17 00:00:00 2001 From: Edwin Noorlander Date: Wed, 12 Nov 2025 08:41:23 +0100 Subject: [PATCH] Enable category tree with limits to prevent 500 errors: max depth 5, max 20 items per category --- config.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/config.php b/config.php index 80aa5fd..8d97779 100755 --- a/config.php +++ b/config.php @@ -54,7 +54,7 @@ try { $items = App\Models\Item::getAll($db); function buildTree($categories, $items, $parentId = null, &$visited = [], $depth = 0) { - if ($depth > 10) return []; // Prevent deep recursion + if ($depth > 5) return []; // Limit depth $tree = []; foreach ($categories as $cat) { if ($cat['parent_id'] == $parentId && !in_array($cat['id'], $visited)) { @@ -65,9 +65,12 @@ try { 'children' => buildTree($categories, $items, $cat['id'], $visited, $depth + 1), 'items' => [] ]; + // Limit items to 20 per category + $itemCount = 0; foreach ($items as $item) { - if ($item['category_id'] == $cat['id']) { + if ($item['category_id'] == $cat['id'] && $itemCount < 20) { $node['items'][] = $item; + $itemCount++; } } $tree[] = $node; @@ -79,7 +82,7 @@ try { $categoryTree = buildTree($categories, $items); function renderTree($nodes, $depth = 0) { - if ($depth > 10) return ''; + if ($depth > 5) return ''; $html = ''; foreach ($nodes as $node) { $html .= '
  • ';