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

[fix] reduce content in sql lab localStorage #7998

Merged

Conversation

graceguo-supercat
Copy link

CATEGORY

Choose one

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

SUMMARY

recent new features increase the size of content in sql lab dropdown list (like tables etc). If we store everything in redux store into localStorage, it's very easy reach localStorage upper limit.

Solution:
remove tables/table options from localStorage.

TEST PLAN

Added unit test for this update.

REVIEWERS

@etr2460 @mistercrunch @michellethomas

export function clearQueryEditors(queryEditors) {
return queryEditors.map(editor =>
// only return selected keys
Object.keys(editor).reduce((accumulator, key) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • We could make PERSISTENT_QUERY_EDITOR_KEYS a Set.
  • filter before reduce may look a bit cleaner.
Object.keys(editor)
  .filter(key => PERSISTENT_QUERY_EDITOR_KEYS.has(key))
  .reduce((acc, key) => {
     // reuse the same acc object instead of spreading into a new object every iteration.
     // naming a constant from function param will get you pass the eslint rule no param assignment
     const output = acc;
     output[key] = editor[key];
     return output; 
  }, {});

Copy link
Author

@graceguo-supercat graceguo-supercat Aug 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const output = acc;
output[key] = editor[key];

this way you will keep changing the original copy of accumulator, which makes no sense to assign to a new variable output. The point of spread function is to make deep copy of the original object, and when you change the deep copy, the original copy is immutable. The purpose of the eslint rule is, do not change the input param right ? even you write in a way that doesn't break the rule, you still changed input param....

Copy link
Contributor

@kristw kristw Aug 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree that the purpose of the eslint rule is promote immutability over mutation, but since nobody will ever use the intermediate objects I think it might be ok to trade off for less memory usage and garbage collection.

This part is not a blocker for me though.

Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one question, otherwise lgtm

however, i think you should make the change Krist recommended

@@ -56,7 +56,10 @@ const sqlLabPersistStateConfig = {
if (path === 'sqlLab') {
subset[path] = {
...state[path],
databases: {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we keep databases around? there aren't that many of them usually

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@codecov-io
Copy link

codecov-io commented Aug 7, 2019

Codecov Report

Merging #7998 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7998      +/-   ##
==========================================
+ Coverage   65.58%   65.62%   +0.04%     
==========================================
  Files         469      469              
  Lines       22413    22419       +6     
  Branches     2431     2431              
==========================================
+ Hits        14699    14712      +13     
+ Misses       7593     7587       -6     
+ Partials      121      120       -1
Impacted Files Coverage Δ
superset/assets/src/SqlLab/App.jsx 0% <ø> (ø) ⬆️
...src/SqlLab/utils/reduxStateToLocalStorageHelper.js 100% <100%> (ø)
.../assets/src/SqlLab/components/AceEditorWrapper.jsx 58.53% <0%> (+1.21%) ⬆️
superset/assets/src/reduxUtils.js 68.96% <0%> (+1.72%) ⬆️
superset/db_engine_specs/postgres.py 95.45% <0%> (+22.72%) ⬆️

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 e830474...643d3da. Read the comment docs.

@graceguo-supercat graceguo-supercat merged commit b380879 into apache:master Aug 7, 2019
etr2460 pushed a commit to airbnb/superset-fork that referenced this pull request Aug 7, 2019
@betodealmeida
Copy link
Member

@graceguo-supercat I'm finishing my PR moving all the state to the backend, I should have it for review early next week.

@graceguo-supercat graceguo-supercat deleted the gg-ReduceLocalStorage branch August 8, 2019 18:55
etr2460 pushed a commit to etr2460/incubator-superset that referenced this pull request Aug 8, 2019
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 28, 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/M 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants