-
Notifications
You must be signed in to change notification settings - Fork 88
Closed
Labels
Description
Terms
- Before you open this issue, I have checked if the issue has already been reported.
UnoPim Version(s) affected
0.2.1
Issue Description
Categories tree widget rendering time more then 10 seconds, and it grows with categories number increasing
Preconditions
Having large amount of categories
Steps to reproduce
- Go to 'Catalog->Categories'
- Create 100 or more categories, or import them from csv
- Click 'Create new category', or edit existing
- Tree widget rendering very long time
Expected Result
Fast rendering of tree
Actual Result
Very long rendering of tree
Screenshots
No response
Additional Context
Obviously reason is converting to JSON entire collection. And solution is quite simple - processing tree before sending it to template. I'd tested with simple method
public function create()
{
$tree = $this->categoryRepository->getCategoryTree(null, ['id']);
$categories = $this->transformCategoryTree($tree);
$leftCategoryFields = $this->categoryFieldRepository->getActiveCategoryFieldsBySection('left');
$rightCategoryFields = $this->categoryFieldRepository->getActiveCategoryFieldsBySection('right');
return view('admin::catalog.categories.create', compact('categories', 'leftCategoryFields', 'rightCategoryFields'));
}
public function transformCategoryTree($categories)
{
return $categories->map(function ($category) {
return [
'id' => $category->id,
'name' => $category->name,
'children' => $category->children && $category->children->isNotEmpty()
? $this->transformCategoryTree($category->children)
: [],
];
})->toArray();
}
And rendering become fast