Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math.max(...array) considered harmful #8575

Merged
merged 2 commits into from Nov 15, 2019
Merged

Conversation

betodealmeida
Copy link
Member

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

In <FilterableTable> we're computing the maximum value of an array using this code snippet:

max_value = Math.max(...some_array);

The problem is that if some_array is big this will trigger the error RangeError: Maximum call stack size exceeded, since the number of arguments passed to the function Math.max is too big.

I fixed it by using reduce instead.

TEST PLAN

Tested with a query that was failing, it now works.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

@khtruong

@betodealmeida betodealmeida changed the title Do not use Math.max Math.max(...array) considered harmful Nov 15, 2019
@codecov-io
Copy link

Codecov Report

Merging #8575 into master will increase coverage by 5.11%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8575      +/-   ##
==========================================
+ Coverage    66.5%   71.62%   +5.11%     
==========================================
  Files         450      118     -332     
  Lines       23117    12587   -10530     
  Branches     2451        0    -2451     
==========================================
- Hits        15375     9016    -6359     
+ Misses       7593     3571    -4022     
+ Partials      149        0     -149
Impacted Files Coverage Δ
superset/db_engine_specs/postgres.py 55.55% <0%> (-27.78%) ⬇️
...sets/src/explore/components/ExploreChartHeader.jsx
superset/assets/src/components/Checkbox.jsx
...perset/assets/src/dashboard/util/getEmptyLayout.js
...ts/src/dashboard/util/getComponentWidthFromDrop.js
.../assets/src/dashboard/reducers/dashboardFilters.js
...rc/explore/components/controls/AnnotationLayer.jsx
superset/assets/src/welcome/DashboardTable.jsx
...erset/assets/src/dashboard/util/injectCustomCss.js
...explore/components/controls/ColorPickerControl.jsx
... and 322 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 78f41b3...df02493. Read the comment docs.

@betodealmeida betodealmeida merged commit 2f77c9f into apache:master Nov 15, 2019
@dpgaspar dpgaspar added the v0.35 label Dec 20, 2019
villebro pushed a commit that referenced this pull request Jan 4, 2020
* Do not use Math.max

* Small fix
@mistercrunch mistercrunch added 🍒 0.35.2 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.36.0 labels Feb 28, 2024
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XS v0.35 🍒 0.35.2 🚢 0.36.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants