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

feat: Add etag caching to dashboard APIs #14357

Merged
merged 1 commit into from
Apr 29, 2021

Conversation

etr2460
Copy link
Member

@etr2460 etr2460 commented Apr 26, 2021

SUMMARY

Reimplementation of #10963 and #11137 now that APIs aren't user specific

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Non etag cached:
Screen Shot 2021-04-26 at 6 04 53 PM

Etag cached:
Screen Shot 2021-04-26 at 6 06 31 PM

TEST PLAN

Unit tests, validate that the proper headers are set on responses, ensure that non-first loads of dashboards load faster, and that dashboard loads after edits load slower and with the fresh data

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

to: @ktmud @suddjian @graceguo-supercat

@@ -54,6 +55,21 @@ def get_datasets_for_dashboard(id_or_slug: str) -> List[Any]:
def get_charts_for_dashboard(id_or_slug: str) -> List[Slice]:
return DashboardDAO.get_by_id_or_slug(id_or_slug).slices

@staticmethod
def get_dashboard_changed_on(id_or_slug: str) -> datetime:
Copy link
Member

@suddjian suddjian Apr 26, 2021

Choose a reason for hiding this comment

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

I believe this could also be affected by datasets changed_on, but adding that would make this more expensive to check. The slices changed_on check could also be skipped for /dashboard/:id_or_slug. Maybe it would be better to have a separate method per endpoint?

@codecov
Copy link

codecov bot commented Apr 26, 2021

Codecov Report

Merging #14357 (091f5a6) into master (bbdb4ee) will increase coverage by 0.17%.
The diff coverage is 58.97%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14357      +/-   ##
==========================================
+ Coverage   76.70%   76.88%   +0.17%     
==========================================
  Files         955      955              
  Lines       48256    48664     +408     
  Branches     6035     6035              
==========================================
+ Hits        37015    37415     +400     
- Misses      11046    11054       +8     
  Partials      195      195              
Flag Coverage Δ
hive 80.74% <58.97%> (-0.03%) ⬇️
javascript 71.30% <ø> (ø)
mysql 81.14% <58.97%> (+0.10%) ⬆️
postgres 81.03% <58.97%> (-0.03%) ⬇️
presto 80.74% <58.97%> (?)
python 81.70% <58.97%> (+0.25%) ⬆️
sqlite 80.78% <58.97%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/utils/cache.py 73.26% <53.33%> (-2.02%) ⬇️
superset/dashboards/dao.py 89.76% <55.55%> (-5.70%) ⬇️
superset/dashboards/api.py 87.67% <83.33%> (-0.10%) ⬇️
superset/models/core.py 89.13% <0.00%> (+0.27%) ⬆️
superset/tasks/async_queries.py 93.40% <0.00%> (+1.34%) ⬆️
superset/utils/core.py 90.17% <0.00%> (+1.42%) ⬆️
superset/connectors/sqla/models.py 90.07% <0.00%> (+1.45%) ⬆️
superset/viz.py 58.43% <0.00%> (+2.93%) ⬆️
superset/db_engine_specs/presto.py 90.31% <0.00%> (+5.89%) ⬆️

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 bbdb4ee...091f5a6. Read the comment docs.

@etr2460 etr2460 force-pushed the erik-ritter--dashboard-etag-caching branch 7 times, most recently from 4e6b5d2 to 8186a35 Compare April 28, 2021 04:21
max_age=0,
raise_for_access=lambda _self, id_or_slug: DashboardDAO.get_by_id_or_slug(
id_or_slug
),
Copy link
Member

Choose a reason for hiding this comment

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

So it seems DashboardDAO.get_by_id_or_slug will be called at least 3 times on first visit (no etag). I'm starting to wonder whether it's worth it to move everything out of the view handler. Maybe some direct function calls would be both more performant and easier to understand.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, i noticed that too. The db call should be very fast since it's indexed, so i didn't think it was too big of a deal. Maybe it's worth caching for the request lifespan though. Honestly, I wonder if sqlalchemy could do something like that for us

@etr2460 etr2460 force-pushed the erik-ritter--dashboard-etag-caching branch from 8186a35 to 7113a5c Compare April 28, 2021 05:00
@etr2460 etr2460 marked this pull request as ready for review April 28, 2021 05:07
@etr2460 etr2460 force-pushed the erik-ritter--dashboard-etag-caching branch from 7113a5c to 091f5a6 Compare April 28, 2021 15:33
@etr2460
Copy link
Member Author

etr2460 commented Apr 28, 2021

:'( why'd you close this @mistercrunch ?

I assume a misclick or a rogue script :P

@etr2460 etr2460 reopened this Apr 28, 2021
Copy link
Member

@ktmud ktmud left a comment

Choose a reason for hiding this comment

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

Tested locally and it seems be working nicely!

@etr2460 etr2460 merged commit bc47bc8 into master Apr 29, 2021
etr2460 pushed a commit to airbnb/superset-fork that referenced this pull request Apr 29, 2021
amitmiran137 pushed a commit to nielsen-oss/superset that referenced this pull request May 3, 2021
* master: (38 commits)
  refactor(native-filters): allow cascading only for filter_select (apache#14441)
  test(maximize-chart): Add tests to maximize chart action (apache#14371)
  fix: fixing mysql error message (apache#14416)
  feat: Logic added to limiting factor column in Query model (apache#13521)
  change relationship (apache#14435)
  fix: bootstrap data permissions (apache#14348)
  fix: parse simple string error message values (apache#14360)
  chore: add stack trace to all calls of logger.error (apache#14382)
  update README with new docs and recordings (apache#14432)
  Renamed impyla from implya in impala.mdx and Renamed PIP package impyla from impala in index.mdx (apache#14425)
  fix(native-filters): fix filter scope error (apache#14426)
  feat: Adding limiting_factor column to Query model (apache#14234)
  feat: Add etag caching to dashboard APIs (apache#14357)
  chore: Moves Card to the components folder (apache#14139)
  feat: Dynamic imports for the Icons component (apache#14318)
  feat: Support env vars configuration for WebSocket server (apache#14398)
  fix: SQLLab role permissions (apache#14372)
  fix(native-filters): always show filters without dataset (apache#14409)
  fix error getting partitionQuery from table.partition (apache#14369)
  refactor: Boostrap to AntD - Tabs (apache#14048)
  ...
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 2024
@mistercrunch mistercrunch deleted the erik-ritter--dashboard-etag-caching branch March 26, 2024 16:10
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/L 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants