dangdtr opened a new pull request, #42476:
URL: https://github.com/apache/superset/pull/42476
### SUMMARY
`QueryContextFactory.create()` resolves the datasource model for the query
context, but each nested `QueryObjectFactory.create()` resolves the same
datasource again. A context with N query objects therefore performs N+1
identical datasource lookups.
This change passes the already-resolved datasource model into
`QueryObjectFactory`. Standalone query-object construction keeps the existing
fallback lookup, while query-context construction reuses one model instance for
every query object. This avoids repeated metadata queries without introducing
request-scoped ORM caching or changing behavior outside the context factory.
The regression test builds a context with two query objects and verifies
that the datasource DAO is called once and that both query objects receive the
context's datasource instance.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable; this is a backend performance change with no UI changes.
### TESTING INSTRUCTIONS
1. Run the query context and query object factory unit tests:
```bash
pytest -q tests/unit_tests/common/test_query_context_factory.py
tests/unit_tests/common/test_query_object_factory.py
```
Expected: `53 passed`.
2. Run pre-commit against the changed files:
```bash
pre-commit run
```
Expected: all applicable hooks pass, including MyPy, Ruff, and Pylint.
`pre-commit run --all-files` was also executed. All backend checks passed,
including MyPy across the full source tree. Unrelated frontend/docs/Helm hooks
could not complete because the local checkout does not have all frontend
dependencies, Yarn, or `helm-docs` installed.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] 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
--
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]