ColtenOuO opened a new pull request, #43017:
URL: https://github.com/apache/superset/pull/43017

   ### 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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to