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: caching on viz with relative time ranges and time compare #10061

Merged
merged 1 commit into from Jun 16, 2020

Conversation

etr2460
Copy link
Member

@etr2460 etr2460 commented Jun 16, 2020

SUMMARY

When loading a recently loaded chart with a relative time range and a time compare selected, the chart renders with the "cached" icons, but it clearly takes far too long to load (like a minute compared to the usual half a second for a cached chart. After investigation, it looks like the cache key isn't consistent for relative time range time compare extra queries. This fixes that issue

TEST PLAN

CI + new unit tests

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

to: @john-bodley @mistercrunch @villebro

@codecov-commenter
Copy link

codecov-commenter commented Jun 16, 2020

Codecov Report

Merging #10061 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10061      +/-   ##
==========================================
- Coverage   70.49%   70.48%   -0.01%     
==========================================
  Files         585      585              
  Lines       31074    31075       +1     
  Branches     3185     3185              
==========================================
- Hits        21905    21904       -1     
- Misses       9060     9061       +1     
- Partials      109      110       +1     
Flag Coverage Δ
#cypress 53.88% <ø> (-0.02%) ⬇️
#javascript 59.49% <ø> (ø)
#python 70.07% <100.00%> (+<0.01%) ⬆️
Impacted Files Coverage Δ
superset/viz.py 57.18% <100.00%> (+0.02%) ⬆️
superset-frontend/src/SqlLab/actions/sqlLab.js 66.15% <0.00%> (-0.66%) ⬇️
.../src/dashboard/components/gridComponents/Chart.jsx 89.88% <0.00%> (+1.12%) ⬆️

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 280ade8...ca8a9fb. Read the comment docs.

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

I looked up how inner_from_dttm and inner_to_dttm is instantiated and used, and it appears they're only used in one place, and even there they get the value of from_dttm/to_dttm: https://github.com/apache/incubator-superset/blob/280ade826c038d7e1172e3291e9dc14ebbce0dc2/superset/viz.py#L1249-L1250
Later on we can see that it is in fact falling back to using from_dttm/to_dttm: https://github.com/apache/incubator-superset/blob/280ade826c038d7e1172e3291e9dc14ebbce0dc2/superset/connectors/sqla/models.py#L997-L1001 and https://github.com/apache/incubator-superset/blob/280ade826c038d7e1172e3291e9dc14ebbce0dc2/superset/connectors/sqla/models.py#L1035-L1047
In addition, QueryObject doesn't support these properties. So it appears they're note really needed, and can be removed, and replaced with from_dttm/to_dttm wherever referenced.

@@ -396,8 +396,9 @@ def cache_key(self, query_obj: QueryObjectDict, **extra: Any) -> str:
cache_dict = copy.copy(query_obj)
cache_dict.update(extra)

for k in ["from_dttm", "to_dttm"]:
del cache_dict[k]
for k in ["from_dttm", "to_dttm", "inner_from_dttm", "inner_to_dttm"]:
Copy link
Member

Choose a reason for hiding this comment

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

@etr2460 can you also make this change in viz_sip38.py? Also we should probably update the comment on line 392 to reflect the change.

Copy link
Member Author

Choose a reason for hiding this comment

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

According to @villebro he'd pull any viz changes into viz_sip38 sometime in the future. is that still the case? will update the comment

Copy link
Member

Choose a reason for hiding this comment

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

Yes, don't worry about it, I'll be making updates to some of the SIP-38 affected files soon and can take care of these changes during that update.

viz.cache_key(qobj), viz.cache_key(qobj, time_compare="12 weeks")
)

qobj["inner_from_dttm"] = "foo"
Copy link
Member

Choose a reason for hiding this comment

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

Could we make this a datetime object for consistency? I personally find unit tests can be a good mechanism for understanding how the code operates and thus ensuring the types are accurate helps to improve the readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

@etr2460
Copy link
Member Author

etr2460 commented Jun 16, 2020

@villebro i think we need to keep inner_from_dttm and inner_to_dttm around, as shortly after setting them, we mutate the original from_dttm and to_dttm attributes on the query object.
https://github.com/apache/incubator-superset/blob/280ade826c038d7e1172e3291e9dc14ebbce0dc2/superset/viz.py#L1259-L1260

I assume there's some reason why we need to keep the original params around, and that's why they're referenced throughout the models

@john-bodley
Copy link
Member

@villebro we probably should double check the logic, i.e., it's clear they get the values of from_dttm and to_dttm at some stage, however it's not initially apparent these are the same from/to per https://github.com/apache/incubator-superset/blob/a3393c1bc424502caa62c7267bd616800c897685/superset/connectors/sqla/models.py#L731.

@etr2460 etr2460 force-pushed the erik-ritter--time-compare-cache branch from 4df9a48 to 87c67fb Compare June 16, 2020 06:40
@john-bodley
Copy link
Member

Here is https://github.com/apache/incubator-superset/blob/280ade826c038d7e1172e3291e9dc14ebbce0dc2/superset/viz.py#L1259

where from_dttm and to_dttm are mutated after having set the inner equivalent.

@etr2460 etr2460 force-pushed the erik-ritter--time-compare-cache branch from 87c67fb to 905500e Compare June 16, 2020 06:57
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

@etr2460 good point, I didn't realize that they were separated to facilitate time shifting. While you're at it, would it be possible to add an additional test that ensures that a different time_compare generates a different cache_key?

@etr2460 etr2460 force-pushed the erik-ritter--time-compare-cache branch from 905500e to ca8a9fb Compare June 16, 2020 07:19
@etr2460
Copy link
Member Author

etr2460 commented Jun 16, 2020

@villebro i added another test case

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM

@etr2460 etr2460 merged commit 7504b1c into apache:master Jun 16, 2020
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.37.0 labels Mar 12, 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/S 🚢 0.37.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants