open-admin
open-admin copied to clipboard
Optimization in select_all function to reduce browser freeze
Optimization in select_all
function to reduce browser freeze
Problem Description
When using the select_all
function within the framework, there is a significant performance issue leading to browser freezing. This seems to be due to the fact that the function currently triggers a click event for each row, causing excessive resource consumption, especially when there are many rows.
https://github.com/open-admin-org/open-admin/blob/8e39330b8f3f3994e36ca2045a7ec56c8075d28f/resources/assets/open-admin/js/open-admin-grid.js#L44
Steps to Reproduce
- Navigate to [specific page or feature where issue occurs].
- Try to select all rows using the
select_all
feature. - Notice that with a high number of rows, the browser becomes unresponsive.
Proposed Solution
Instead of triggering a click event for each row, I suggest changing the method to directly update the checked
property of each checkbox. This reduces the unnecessary overhead of repeatedly triggering events.
Original Code:
box.click();
Optimized Code:
box.checked = checkbox.checked;
Original Code:
- Significant performance improvement, especially with a large number of rows.
- Reduces the likelihood of the browser becoming unresponsive.
@haboshi thanks for the tip!
The reason for the click, was because it should invert the selection.
I was not aware of the ^= operator yet.
now using:
box.checked ^= checkbox.checked;
Fixed in dev-branch, will release soon.