Skip to content

perf(dashboard): batch dataset lookups during dashboard export - #43017

Open
ColtenOuO wants to merge 1 commit into
apache:masterfrom
ColtenOuO:fix/dashboard-export-batch-dataset-lookup
Open

perf(dashboard): batch dataset lookups during dashboard export#43017
ColtenOuO wants to merge 1 commit into
apache:masterfrom
ColtenOuO:fix/dashboard-export-batch-dataset-lookup

Conversation

@ColtenOuO

Copy link
Copy Markdown

SUMMARY

ExportDashboardsCommand._file_content and _export issued a separate DatasetDAO.find_by_id query per native-filter target and per chart-customization target, even when multiple targets referenced the same dataset — a common case, since one dataset is often targeted by several filters on the same dashboard. _export compounded this by re-running a full ExportDatasetsCommand([id]).run() (a recursive export_to_dict plus the dataset's database export) for every occurrence of the same dataset id, with the duplicate output only discarded later by filename dedup in the outer export loop.

This change collects all referenced dataset ids up front, resolves them in a single batched DatasetDAO.find_by_ids() call, and exports each unique dataset exactly once via a single ExportDatasetsCommand(unique_ids).run() call. Behavior is unchanged — same UUID substitution, same "dataset not found" fallback/warning, same file output — just without the redundant DB round-trips and re-serialization work.

Benchmarked against a real SQLite session (DatasetDAO.find_by_id × N vs. a single find_by_ids): ~2.4x faster at 3 unique referenced datasets, ~6.2x at 10, ~9.4x at 20. This is against local SQLite with no network latency — on a production Postgres/MySQL backend the per-query round-trip cost is higher, so the absolute savings would be larger.

TESTING INSTRUCTIONS

  • pytest tests/unit_tests/commands/dashboard/export_test.py -q — 18 tests pass, including two new regression tests (test_file_content_batches_dataset_lookup_across_targets, test_export_batches_dataset_export_across_targets) that assert DatasetDAO.find_by_id is never called and DatasetDAO.find_by_ids / ExportDatasetsCommand are each called exactly once, even when several targets reference overlapping dataset ids. Verified these fail against the pre-fix implementation (3 calls to find_by_id) and pass against the fix.
  • ruff check / ruff format --check on both changed files pass.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

ExportDashboardsCommand issued a separate DatasetDAO.find_by_id query
(and, for _export, a separate ExportDatasetsCommand run) per native
filter / chart customization target, even when multiple targets
referenced the same dataset — a common case since one dataset is often
targeted by several filters. Batch the lookups with find_by_ids and
deduplicate before exporting, so each referenced dataset is queried and
exported exactly once regardless of how many targets reference it.
@dosubot dosubot Bot added dashboard:export Related to exporting dashboards dashboard:performance Related to Dashboard performance labels Aug 10, 2026
@bito-code-review

bito-code-review Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #93725d

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: a44bae3..a44bae3
    • superset/commands/dashboard/export.py
    • tests/unit_tests/commands/dashboard/export_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.36364% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.42%. Comparing base (651c046) to head (a44bae3).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
superset/commands/dashboard/export.py 36.36% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #43017   +/-   ##
=======================================
  Coverage   66.42%   66.42%           
=======================================
  Files        2861     2861           
  Lines      161614   161615    +1     
  Branches    37223    37222    -1     
=======================================
+ Hits       107349   107355    +6     
+ Misses      52223    52217    -6     
- Partials     2042     2043    +1     
Flag Coverage Δ
hive 38.21% <0.00%> (+<0.01%) ⬆️
mysql 57.76% <36.36%> (+<0.01%) ⬆️
postgres 57.82% <36.36%> (+<0.01%) ⬆️
presto 40.18% <0.00%> (+<0.01%) ⬆️
python 59.20% <36.36%> (+<0.01%) ⬆️
sqlite 57.43% <36.36%> (+<0.01%) ⬆️
unit 100.00% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rusackas
rusackas requested review from EnxDev and rusackas August 10, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dashboard:export Related to exporting dashboards dashboard:performance Related to Dashboard performance size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant